@@ -66,19 +66,45 @@ 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
+
76
100
return {
77
101
authAccess : "wallet" ,
78
102
aptos : new Aptos ( config ) ,
79
- signer : parameters . transport as AptosBrowserWallet
103
+ // Create a signer object that includes the accountAddress property
104
+ signer : { accountAddress : account . address } as AptosBrowserWallet
80
105
}
81
106
}
107
+
82
108
throw new Error ( "Invalid Aptos transport" )
83
109
}
84
110
@@ -105,7 +131,12 @@ export const createAptosClient = (clientParameters: AptosClientParameters) => {
105
131
. extend ( _ => ( {
106
132
// A helper to get the underlying Aptos client.
107
133
// We default to "key" if an account was provided.
108
- getAptosClient : async ( ) => await getAptosClient ( { ...clientParameters , authAccess : "key" } )
134
+ getAptosClient : async ( ) => {
135
+ console . info ( "clientParameters" , clientParameters )
136
+ console . info ( "getAptosClient" , getAptosClient )
137
+ const authAccess = clientParameters . account ? "key" : "wallet"
138
+ return await getAptosClient ( { ...clientParameters , authAccess } )
139
+ }
109
140
// clientParameters.account
110
141
// ? await getAptosClient({ ...clientParameters, authAccess: "key" })
111
142
// : await getAptosClient({ ...clientParameters, authAccess: "wallet" })
0 commit comments