Skip to content

Commit

Permalink
chore(app): creating aptos client according to wallet wip
Browse files Browse the repository at this point in the history
Signed-off-by: Kaan Caglan <[email protected]>
  • Loading branch information
Caglankaan committed Feb 28, 2025
1 parent c4ed99f commit 134828e
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions typescript-sdk/src/aptos/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,45 @@ async function getAptosClient(
}
}

// if (parameters.authAccess === "wallet") {
// if (typeof parameters.transport !== "object") {
// throw new Error("Invalid Aptos transport")
// }
// const networkInfo = await parameters.transport.getNetwork()
// const network = networkInfo.name.toLowerCase() === "mainnet" ? Network.MAINNET : Network.TESTNET
// const config = new AptosConfig({ fullnode: networkInfo.url, network })
// return {
// authAccess: "wallet",
// aptos: new Aptos(config),
// signer: parameters.transport as AptosBrowserWallet
// }
// }
if (parameters.authAccess === "wallet") {
if (typeof parameters.transport !== "object") {
throw new Error("Invalid Aptos transport")
}
const networkInfo = await parameters.transport.getNetwork()
const network = networkInfo.name.toLowerCase() === "mainnet" ? Network.MAINNET : Network.TESTNET
const network =
networkInfo.name.toLowerCase() === "mainnet" ? Network.MAINNET : Network.TESTNET
const config = new AptosConfig({ fullnode: networkInfo.url, network })

// Get the connected account; this may require calling a dedicated method
const account = await parameters.transport.getAccount?.() ||
// Or retrieve from your store if you already connected:
{ address: /* your stored account address */ "" }

if (!account.address) {
throw new Error("No account address found from the wallet")
}

return {
authAccess: "wallet",
aptos: new Aptos(config),
signer: parameters.transport as AptosBrowserWallet
// Create a signer object that includes the accountAddress property
signer: { accountAddress: account.address } as AptosBrowserWallet
}
}

throw new Error("Invalid Aptos transport")
}

Expand All @@ -105,7 +131,10 @@ export const createAptosClient = (clientParameters: AptosClientParameters) => {
.extend(_ => ({
// A helper to get the underlying Aptos client.
// We default to "key" if an account was provided.
getAptosClient: async () => await getAptosClient({ ...clientParameters, authAccess: "key" })
getAptosClient: async () => {
const authAccess = clientParameters.account ? "key" : "wallet"
return await getAptosClient({ ...clientParameters, authAccess })
}
// clientParameters.account
// ? await getAptosClient({ ...clientParameters, authAccess: "key" })
// : await getAptosClient({ ...clientParameters, authAccess: "wallet" })
Expand Down

0 comments on commit 134828e

Please sign in to comment.