Skip to content

Commit

Permalink
added additional chainId to useEtherspotBalances
Browse files Browse the repository at this point in the history
  • Loading branch information
poocart committed Feb 6, 2024
1 parent 7dcfea8 commit 1526952
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.7.1] - 2024-02-06

### Added Changes
- Added `chainId` param to `useEtherspotBalances` hook's `getBalances` method

## [0.7.0] - 2024-01-30

### Added Changes
Expand Down
5 changes: 5 additions & 0 deletions __tests__/hooks/useEtherspotBalances.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ describe('useEtherspotBalances()', () => {
const accountBalancesPolygon = await result.current.getAccountBalances();
expect(accountBalancesPolygon.length).toEqual(1);
expect(accountBalancesPolygon[0].balance.toString()).toEqual(ethers.utils.parseEther('0').toString());

const accountBalancesManualMainnet = await result.current.getAccountBalances('0xAb4C67d8D7B248B2fA6B638C645466065fE8F1F1', 1);
expect(accountBalancesManualMainnet.length).toEqual(2);
expect(accountBalancesManualMainnet[1].token).not.toBeNull();
expect(accountBalancesManualMainnet[1].balance.toString()).toEqual(ethers.utils.parseEther('69').toString());
});
})
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@etherspot/transaction-kit",
"description": "React Etherspot Transaction Kit",
"version": "0.7.0",
"version": "0.7.1",
"main": "dist/cjs/index.js",
"scripts": {
"rollup:build": "NODE_OPTIONS=--max-old-space-size=8192 rollup -c",
Expand Down
13 changes: 8 additions & 5 deletions src/hooks/useEtherspotBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ interface IEtherspotBalancesHook {
* @returns {IEtherspotBalancesHook} - hook method to fetch Etherspot account balances
*/
const useEtherspotBalances = (chainId?: number): IEtherspotBalancesHook => {
const { getSdk, chainId: defaultChainId } = useEtherspot();
const { getSdk, chainId: etherspotChainId } = useEtherspot();

const balancesChainId = useMemo(() => {
const defaultChainId = useMemo(() => {
if (chainId) return chainId;
return defaultChainId;
}, [chainId, defaultChainId]);
return etherspotChainId;
}, [chainId, etherspotChainId]);

const getAccountBalances = async (accountAddress?: string) => {
const getAccountBalances = async (
accountAddress?: string,
balancesChainId: number = defaultChainId,
) => {
const sdkForChainId = await getSdk(balancesChainId);

const balancesForAccount = accountAddress ?? await sdkForChainId.getCounterFactualAddress();
Expand Down

0 comments on commit 1526952

Please sign in to comment.