Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit 301cb4e

Browse files
authored
use provider to get balance and address -> getAddress() (#441)
* use provider to get balance and address -> getAddress() * udpate tests * v2.3.5-0
1 parent ba3c3c3 commit 301cb4e

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
22

3-
[Home](./index.md) &gt; [@thirdweb-dev/sdk](./sdk.md) &gt; [UserWallet](./sdk.userwallet.md) &gt; [address](./sdk.userwallet.address.md)
3+
[Home](./index.md) &gt; [@thirdweb-dev/sdk](./sdk.md) &gt; [UserWallet](./sdk.userwallet.md) &gt; [getAddress](./sdk.userwallet.getaddress.md)
44

5-
## UserWallet.address() method
5+
## UserWallet.getAddress() method
66

77
Get the currently connected address
88

99
<b>Signature:</b>
1010

1111
```typescript
12-
address(): Promise<string>;
12+
getAddress(): Promise<string>;
1313
```
1414
<b>Returns:</b>
1515

@@ -19,6 +19,6 @@ Promise&lt;string&gt;
1919

2020

2121
```javascript
22-
const address = await sdk.wallet.address();
22+
const address = await sdk.wallet.getAddress();
2323
```
2424

docs/sdk.userwallet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const balance = await sdk.wallet.balance();
2929

3030
| Method | Modifiers | Description |
3131
| --- | --- | --- |
32-
| [address()](./sdk.userwallet.address.md) | | Get the currently connected address |
3332
| [balance(currencyAddress)](./sdk.userwallet.balance.md) | | Fetch the native or ERC20 token balance of this wallet |
33+
| [getAddress()](./sdk.userwallet.getaddress.md) | | Get the currently connected address |
3434
| [onNetworkUpdated(network)](./sdk.userwallet.onnetworkupdated.md) | | |
3535
| [sendRawTransaction(transactionRequest)](./sdk.userwallet.sendrawtransaction.md) | | Send a raw transaction to the blockchain from the connected wallet |
3636
| [sign(message)](./sdk.userwallet.sign.md) | | Sign any message with the connected wallet private key |

etc/sdk.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5313,8 +5313,8 @@ export type UploadResult = {
53135313
// @public
53145314
export class UserWallet {
53155315
constructor(network: NetworkOrSignerOrProvider, options: SDKOptions);
5316-
address(): Promise<string>;
53175316
balance(currencyAddress?: string): Promise<CurrencyValue>;
5317+
getAddress(): Promise<string>;
53185318
// (undocumented)
53195319
onNetworkUpdated(network: NetworkOrSignerOrProvider): void;
53205320
sendRawTransaction(transactionRequest: providers.TransactionRequest): Promise<TransactionResult>;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@thirdweb-dev/sdk",
3-
"version": "2.3.4",
3+
"version": "2.3.5-0",
44
"description": "The main thirdweb SDK.",
55
"repository": {
66
"type": "git",

src/core/wallet/UserWallet.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,26 @@ export class UserWallet {
105105
): Promise<CurrencyValue> {
106106
const signer = this.connection.getSigner();
107107
invariant(signer, "Wallet not connected");
108+
const provider = this.connection.getProvider();
108109
let balance: BigNumber;
109110
if (isNativeToken(currencyAddress)) {
110-
balance = await signer.getBalance();
111+
balance = await provider.getBalance(await this.getAddress());
111112
} else {
112113
balance = await this.createErc20(currencyAddress).readContract.balanceOf(
113-
await this.address(),
114+
await this.getAddress(),
114115
);
115116
}
116-
return await fetchCurrencyValue(
117-
this.connection.getProvider(),
118-
currencyAddress,
119-
balance,
120-
);
117+
return await fetchCurrencyValue(provider, currencyAddress, balance);
121118
}
122119

123120
/**
124121
* Get the currently connected address
125122
* @example
126123
* ```javascript
127-
* const address = await sdk.wallet.address();
124+
* const address = await sdk.wallet.getAddress();
128125
* ```
129126
*/
130-
async address(): Promise<string> {
127+
async getAddress(): Promise<string> {
131128
return await this.connectedWallet().getAddress();
132129
}
133130

test/wallet.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ describe("Wallet", async () => {
4444

4545
it("should fetch addresses", async () => {
4646
sdk.updateSignerOrProvider(adminWallet);
47-
expect(await sdk.wallet.address()).to.eq(adminWallet.address);
47+
expect(await sdk.wallet.getAddress()).to.eq(adminWallet.address);
4848
sdk.updateSignerOrProvider(samWallet);
49-
expect(await sdk.wallet.address()).to.eq(samWallet.address);
49+
expect(await sdk.wallet.getAddress()).to.eq(samWallet.address);
5050
});
5151
});

0 commit comments

Comments
 (0)