Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
fix problem with account balance showing 0
Browse files Browse the repository at this point in the history
  • Loading branch information
varex83 committed Nov 7, 2023
1 parent 54de093 commit 4f476fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion plugin/src/components/DevnetAccountSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const DevnetAccountSelector: React.FC = () => {
6,
4
)}
(${getRoundedNumber(weiToEth(Number(account.initial_balance)), 2)} ether)`
(${getRoundedNumber(weiToEth(account.initial_balance), 2)} ether)`
}
</option>
)
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/types/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum ZksyncChainId {
}

interface DevnetAccount {
initial_balance: string
initial_balance: number
address: string
private_key: string
}
Expand Down
15 changes: 10 additions & 5 deletions plugin/src/utils/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const getAccounts = async (customDevnetUrl: string): Promise<DevnetAccount[]> =>
} catch (error) {
console.error(`Failed to get balance for address ${address}: `, error);
return {
initial_balance: '0',
initial_balance: 0,
address,
private_key
} as DevnetAccount;
Expand All @@ -75,7 +75,7 @@ const updateBalances = async (
): Promise<DevnetAccount[]> => {
const accountPromises: Promise<DevnetAccount>[] = accounts.map(async (account: DevnetAccount) => {
try {
const initial_balance = await getAccountBalance(account.address) || '0';
const initial_balance = await getAccountBalance(account.address) || 0;

return {
initial_balance,
Expand All @@ -85,7 +85,7 @@ const updateBalances = async (
} catch (error) {
console.error(`Failed to get balance for address ${account.address}: `, error);
return {
initial_balance: '0',
initial_balance: 0,
address: account.address,
private_key: account.private_key
} as DevnetAccount;
Expand All @@ -98,7 +98,7 @@ const updateBalances = async (
const getAccountBalance = async (
address: string,
customDevnetUrl: string = devnetUrl
): Promise<any> => {
): Promise<number> => {
const response = await fetch(`${customDevnetUrl}`, {
method: 'POST',
headers: {
Expand All @@ -112,7 +112,12 @@ const getAccountBalance = async (
})
})
const account = await response.json()
return account.result

const number_hex = account.result

const number = parseInt(number_hex, 16)

return number
}

const getDevnetUrl = (network: string): string => {
Expand Down

0 comments on commit 4f476fc

Please sign in to comment.