Skip to content

Commit 944d8af

Browse files
authored
Add EVM token whitelist for balance display (#86)
* add erc20 tokens whitelist * bump version 2.4.2
1 parent 0258681 commit 944d8af

4 files changed

Lines changed: 41 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "mybucks-online",
33
"description": "Web app for Mybucks.online — a seedless wallet and gifting wallet: disposable gift wallets, fund and share via secure 1-click URL. Browser-only (no servers, database, or install). For airdrops, giveaways, campaigns, and instant onboarding.",
44
"private": true,
5-
"version": "2.4.1",
5+
"version": "2.4.2",
66
"type": "module",
77
"keywords": [
88
"mybucks",

src/lib/account/evm.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Contract, ethers } from "ethers";
44

55
import { EVM_NETWORKS, NETWORK } from "@mybucks/lib/conf";
66
import IERC20 from "@mybucks/lib/erc20.json";
7+
import { isWhitelistedToken } from "@mybucks/lib/tokenWhitelist";
78
import {
89
getErc20TokenHistory,
910
getNativeAndErc20TokenBalances,
@@ -68,9 +69,14 @@ class EvmAccount {
6869
const isNative = token.native_token || false;
6970
if (isNative) return true;
7071

71-
return defaultTokensList.find(
72-
({ address }) =>
73-
address.toLowerCase() === token.token_address.toLowerCase(),
72+
const tokenAddress = token.token_address;
73+
return (
74+
isWhitelistedToken(this.chainId, tokenAddress) ||
75+
defaultTokensList.some(
76+
({ address, chainId }) =>
77+
chainId === this.chainId &&
78+
address.toLowerCase() === tokenAddress.toLowerCase(),
79+
)
7480
);
7581
})
7682
.map((token) => {

src/lib/tokenWhitelist.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import whitelists from "@mybucks/lib/whitelists.json";
2+
import { EVM_NETWORKS } from "@mybucks/lib/conf";
3+
4+
const networkNameToChainId = Object.fromEntries(
5+
EVM_NETWORKS.map((n) => [n.name, n.chainId]),
6+
);
7+
8+
const whitelistKeys = new Set(
9+
whitelists
10+
.map((entry) => {
11+
const chainId = entry.chainId ?? networkNameToChainId[entry.network];
12+
if (!chainId || !entry.address) {
13+
return null;
14+
}
15+
return `${chainId}:${entry.address.toLowerCase()}`;
16+
})
17+
.filter(Boolean),
18+
);
19+
20+
export function isWhitelistedToken(chainId, tokenAddress) {
21+
if (!tokenAddress) {
22+
return false;
23+
}
24+
return whitelistKeys.has(`${chainId}:${tokenAddress.toLowerCase()}`);
25+
}

src/lib/whitelists.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"address": "0xA3f751662e282E83EC3cBc387d225Ca56dD63D3A",
4+
"network": "polygon"
5+
}
6+
]

0 commit comments

Comments
 (0)