From 14dc67f77c97359f98bdd8c8ff655131d757ab3d Mon Sep 17 00:00:00 2001 From: PhilippeR26 Date: Tue, 5 Nov 2024 16:58:27 +0100 Subject: [PATCH 1/3] docs: correction of lib name for WalletAccount --- www/docs/guides/walletAccount.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/docs/guides/walletAccount.md b/www/docs/guides/walletAccount.md index 6497f4cd1..d52142f19 100644 --- a/www/docs/guides/walletAccount.md +++ b/www/docs/guides/walletAccount.md @@ -32,7 +32,7 @@ Using the `get-starknet-core` v4 library, you can create your own UI and logic t So, you instantiate a new WalletAccount with : ```typescript -import { connect } from 'get-starknet'; // v4.0.0 min +import { connect } from '@starknet-io/get-starknet'; // v4.0.3 min import { WalletAccount } from 'starknet'; // v6.10.0 min const myFrontendProviderUrl = 'https://free-rpc.nethermind.io/sepolia-juno/v0_7'; // standard UI to select a wallet : From 58b674aacc4a4eab0f8317079cd4baeb78f8cacd Mon Sep 17 00:00:00 2001 From: PhilippeR26 Date: Tue, 5 Nov 2024 17:02:09 +0100 Subject: [PATCH 2/3] ci: revert --- www/docs/guides/walletAccount.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/docs/guides/walletAccount.md b/www/docs/guides/walletAccount.md index 6497f4cd1..d52142f19 100644 --- a/www/docs/guides/walletAccount.md +++ b/www/docs/guides/walletAccount.md @@ -32,7 +32,7 @@ Using the `get-starknet-core` v4 library, you can create your own UI and logic t So, you instantiate a new WalletAccount with : ```typescript -import { connect } from 'get-starknet'; // v4.0.0 min +import { connect } from '@starknet-io/get-starknet'; // v4.0.3 min import { WalletAccount } from 'starknet'; // v6.10.0 min const myFrontendProviderUrl = 'https://free-rpc.nethermind.io/sepolia-juno/v0_7'; // standard UI to select a wallet : From 5badc10e589b0f035abe971f5bdb198dd928bc54 Mon Sep 17 00:00:00 2001 From: PhilippeR26 Date: Fri, 8 Nov 2024 09:44:19 +0100 Subject: [PATCH 3/3] chore: wallet account with no fetch in constructor --- src/wallet/account.ts | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/wallet/account.ts b/src/wallet/account.ts index 8a1bccffc..941cc6c5a 100644 --- a/src/wallet/account.ts +++ b/src/wallet/account.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable no-underscore-dangle */ import type { Signature, AccountChangeEventHandler, @@ -17,6 +19,8 @@ import { ProviderOptions, TypedData, UniversalDeployerContractPayload, + type BlockIdentifier, + type Nonce, } from '../types'; import { extractContractHashes } from '../utils/contract'; import { stringify } from '../utils/json'; @@ -38,8 +42,6 @@ import { StarknetChainId } from '../constants'; // Represent 'Selected Active' Account inside Connected Wallet export class WalletAccount extends Account implements AccountInterface { - public address: string = ''; - public walletProvider: StarknetWalletProvider; constructor( @@ -49,7 +51,6 @@ export class WalletAccount extends Account implements AccountInterface { ) { super(providerOrOptions, '', '', cairoVersion); // At this point unknown address this.walletProvider = walletProvider; - // Update Address on change this.walletProvider.on('accountsChanged', (res) => { if (!res) return; @@ -63,18 +64,22 @@ export class WalletAccount extends Account implements AccountInterface { // At the moment channel is stateless but it could change this.channel.setChainId(res as StarknetChainId); }); + } - // Get and Set Address !!! Post constructor initial empty string - walletProvider - .request({ + public async getAddress(): Promise { + if (!this.address) { + console.log('SNJS-WA.getAddress: define WA address.'); + const response = await this.walletProvider.request({ type: 'wallet_requestAccounts', params: { silent_mode: false, }, - }) - .then((res) => { - this.address = res[0].toLowerCase(); }); + console.log('SNJS-getAddress-A'); + this.address = response[0].toLowerCase(); + console.log('SNJS-getAddress-B'); + } + return this.address; } /** @@ -114,6 +119,16 @@ export class WalletAccount extends Account implements AccountInterface { /** * ACCOUNT METHODS */ + + override async getNonce(blockIdentifier?: BlockIdentifier): Promise { + await this.getAddress(); + return super.getNonce(blockIdentifier); + } + + // ************************ + // TODO : override the 13 other account methods that uses the account address property (fortunately, all are async) + // *********************** + override execute(calls: AllowArray) { const txCalls = [].concat(calls as any).map((it) => { const { contractAddress, entrypoint, calldata } = it; @@ -157,6 +172,7 @@ export class WalletAccount extends Account implements AccountInterface { override async deploy( payload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[] ): Promise { + await this.getAddress(); const { calls, addresses } = buildUDCCall(payload, this.address); const invokeResponse = await this.execute(calls);