Skip to content

Commit f322eee

Browse files
committed
chore(app): creating aptos client according to wallet wip
Signed-off-by: Kaan Caglan <caglankaan@gmail.com>
1 parent c4ed99f commit f322eee

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed

typescript-sdk/src/aptos/client.ts

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ async function getAptosClient(
3939
parameters: AptosClientParameters & { authAccess: "key" }
4040
): Promise<{ authAccess: "key"; aptos: Aptos; signer: AptosAccount }>
4141

42-
// async function getAptosClient(
43-
// parameters: AptosClientParameters & { authAccess: "wallet" }
44-
// ): Promise<{ authAccess: "wallet"; aptos: Aptos; signer: AptosBrowserWallet }>
42+
async function getAptosClient(
43+
parameters: AptosClientParameters & { authAccess: "wallet" }
44+
): Promise<{ authAccess: "wallet"; aptos: Aptos; signer: AptosBrowserWallet }>
4545

4646
async function getAptosClient(
4747
parameters: AptosClientParameters & { authAccess: AuthAccess }
@@ -66,19 +66,49 @@ async function getAptosClient(
6666
}
6767
}
6868

69+
// if (parameters.authAccess === "wallet") {
70+
// if (typeof parameters.transport !== "object") {
71+
// throw new Error("Invalid Aptos transport")
72+
// }
73+
// const networkInfo = await parameters.transport.getNetwork()
74+
// const network = networkInfo.name.toLowerCase() === "mainnet" ? Network.MAINNET : Network.TESTNET
75+
// const config = new AptosConfig({ fullnode: networkInfo.url, network })
76+
// return {
77+
// authAccess: "wallet",
78+
// aptos: new Aptos(config),
79+
// signer: parameters.transport as AptosBrowserWallet
80+
// }
81+
// }
6982
if (parameters.authAccess === "wallet") {
7083
if (typeof parameters.transport !== "object") {
7184
throw new Error("Invalid Aptos transport")
7285
}
7386
const networkInfo = await parameters.transport.getNetwork()
74-
const network = networkInfo.name.toLowerCase() === "mainnet" ? Network.MAINNET : Network.TESTNET
87+
const network =
88+
networkInfo.name.toLowerCase() === "mainnet" ? Network.MAINNET : Network.TESTNET
7589
const config = new AptosConfig({ fullnode: networkInfo.url, network })
90+
91+
// Get the connected account; this may require calling a dedicated method
92+
const account = await parameters.transport.getAccount?.() ||
93+
// Or retrieve from your store if you already connected:
94+
{ address: /* your stored account address */ "" }
95+
96+
if (!account.address) {
97+
throw new Error("No account address found from the wallet")
98+
}
99+
100+
// Create a signer by merging the wallet's methods with the account address.
101+
const signer = Object.assign({}, parameters.transport, {
102+
accountAddress: account.address
103+
}) as AptosBrowserWallet
104+
76105
return {
77106
authAccess: "wallet",
78107
aptos: new Aptos(config),
79-
signer: parameters.transport as AptosBrowserWallet
108+
signer: signer
80109
}
81110
}
111+
82112
throw new Error("Invalid Aptos transport")
83113
}
84114

@@ -105,7 +135,18 @@ export const createAptosClient = (clientParameters: AptosClientParameters) => {
105135
.extend(_ => ({
106136
// A helper to get the underlying Aptos client.
107137
// We default to "key" if an account was provided.
108-
getAptosClient: async () => await getAptosClient({ ...clientParameters, authAccess: "key" })
138+
getAptosClient: async () => {
139+
console.info("clientParameters", clientParameters)
140+
console.info("getAptosClient", getAptosClient)
141+
// const authAccess = clientParameters.account ? "key" : "wallet"
142+
143+
// return await getAptosClient({ ...clientParameters, authAccess })
144+
if (clientParameters.account) {
145+
return await getAptosClient({ ...clientParameters, authAccess: "key" })
146+
} else {
147+
return await getAptosClient({ ...clientParameters, authAccess: "wallet" })
148+
}
149+
}
109150
// clientParameters.account
110151
// ? await getAptosClient({ ...clientParameters, authAccess: "key" })
111152
// : await getAptosClient({ ...clientParameters, authAccess: "wallet" })

0 commit comments

Comments
 (0)