Skip to content

Commit

Permalink
chore: general polishing of transfer page
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Oct 27, 2023
1 parent 44dcf2d commit 629fcaf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/lib/evm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,20 @@ export class EvmSession {
const contract = new ethers.Contract(token.address, erc20_abi, this.signer);

wei = await contract.balanceOf(this.address)

} else if (token?.nativeToken) {
wei = await this.signer.getBalance()
} else {
throw new Error('Non native token must have an address.')
}

return Asset.from(formatToken(ethers.utils.formatEther(wei), token.name))
const decimals = token.decimals

if (token.decimals === 18) {
return Asset.from(Number(ethers.utils.formatEther(wei)), token.name)
} else {
return Asset.from(fromWei(wei, decimals), token.name)
}
}

getBalances() {
Expand Down Expand Up @@ -343,3 +350,7 @@ export async function startEvmSession(): Promise<EvmSession | undefined> {

return evmSession
}

export function fromWei(wei: BigNumber, decimals: number) {
return wei.toNumber() / Math.pow(10, decimals);
}
2 changes: 1 addition & 1 deletion src/pages/transfer/form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
$: {
if (from) {
toOptions = fromOptions.filter((token) => token.name !== from?.name)
toOptions = fromOptions.filter((token) => token.name !== from?.name) // this needs to only show options which involve the same token
} else {
toOptions = fromOptions
}
Expand Down

0 comments on commit 629fcaf

Please sign in to comment.