@@ -39,9 +39,9 @@ async function getAptosClient(
39
39
parameters : AptosClientParameters & { authAccess : "key" }
40
40
) : Promise < { authAccess : "key" ; aptos : Aptos ; signer : AptosAccount } >
41
41
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 } >
45
45
46
46
async function getAptosClient (
47
47
parameters : AptosClientParameters & { authAccess : AuthAccess }
@@ -66,19 +66,49 @@ async function getAptosClient(
66
66
}
67
67
}
68
68
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
+ // }
69
82
if ( parameters . authAccess === "wallet" ) {
70
83
if ( typeof parameters . transport !== "object" ) {
71
84
throw new Error ( "Invalid Aptos transport" )
72
85
}
73
86
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
75
89
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
+
76
105
return {
77
106
authAccess : "wallet" ,
78
107
aptos : new Aptos ( config ) ,
79
- signer : parameters . transport as AptosBrowserWallet
108
+ signer : signer
80
109
}
81
110
}
111
+
82
112
throw new Error ( "Invalid Aptos transport" )
83
113
}
84
114
@@ -105,7 +135,18 @@ export const createAptosClient = (clientParameters: AptosClientParameters) => {
105
135
. extend ( _ => ( {
106
136
// A helper to get the underlying Aptos client.
107
137
// 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
+ }
109
150
// clientParameters.account
110
151
// ? await getAptosClient({ ...clientParameters, authAccess: "key" })
111
152
// : await getAptosClient({ ...clientParameters, authAccess: "wallet" })
0 commit comments