feat: Load default ERC20 Tokens for existing ETH and Polygon Wallets (#2274)

Konstantin Ullrich committed May 15, 2025 at 21:57 UTC c12daced403660399188e64ebeb9dae306a18c5d
8 files changed +24 -9
cw_core/lib/crypto_currency.dart
+1 -1
@@ -232,7 +232,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
232 static const ton = CryptoCurrency(title: 'TON', fullName: 'Toncoin', raw: 95, name: 'ton', iconPath: 'assets/images/ton_icon.png', decimals: 8);
233 static const zano = CryptoCurrency(title: 'ZANO', tag: 'ZANO', fullName: 'Zano', raw: 96, name: 'zano', iconPath: 'assets/images/zano_icon.png', decimals: 12);
234 static const flip = CryptoCurrency(title: 'FLIP', tag: 'ETH', fullName: 'Chainflip', raw: 97, name: 'flip', iconPath: 'assets/images/flip_icon.png', decimals: 18);
235 - static const deuro = CryptoCurrency(title: 'DEURO', tag: 'ETH', fullName: 'Digital Euro', raw: 98, name: 'deuro', iconPath: 'assets/images/deuro_icon.png', decimals: 18);
235 + static const deuro = CryptoCurrency(title: 'DEURO', tag: 'ETH', fullName: 'Decentralized Euro', raw: 98, name: 'deuro', iconPath: 'assets/images/deuro_icon.png', decimals: 18);
236
237 static final Map<int, CryptoCurrency> _rawCurrencyMap =
238 [...all, ...havenCurrencies].fold<Map<int, CryptoCurrency>>(<int, CryptoCurrency>{}, (acc, item) {
cw_ethereum/lib/default_ethereum_erc20_tokens.dart
+1 -1
@@ -18,7 +18,7 @@ class DefaultEthereumErc20Tokens {
18 enabled: true,
19 ),
20 Erc20Token(
21 - name: "Digital Euro",
21 + name: "Decentralized Euro",
22 symbol: "DEURO",
23 contractAddress: "0xbA3f535bbCcCcA2A154b573Ca6c5A49BAAE0a3ea",
24 decimal: 18,
cw_ethereum/lib/ethereum_wallet.dart
+6 -3
@@ -31,11 +31,14 @@ class EthereumWallet extends EVMChainWallet {
31 }) : super(nativeCurrency: CryptoCurrency.eth);
32
33 @override
34 - void addInitialTokens() {
34 + void addInitialTokens([bool isMigration = false]) {
35 final initialErc20Tokens = DefaultEthereumErc20Tokens().initialErc20Tokens;
36
37 - for (var token in initialErc20Tokens) {
38 - evmChainErc20TokensBox.put(token.contractAddress, token);
37 + for (final token in initialErc20Tokens) {
38 + if (!evmChainErc20TokensBox.containsKey(token.contractAddress)) {
39 + if (isMigration) token.enabled = false;
40 + evmChainErc20TokensBox.put(token.contractAddress, token);
41 + }
42 }
43 }
44
cw_ethereum/lib/ethereum_wallet_service.dart
+1
@@ -53,6 +53,7 @@ class EthereumWalletService extends EVMChainWalletService<EthereumWallet> {
53 );
54
55 await wallet.init();
56 + wallet.addInitialTokens(true);
57 await wallet.save();
58 saveBackup(name);
59 return wallet;
cw_evm/lib/evm_chain_wallet.dart
+1 -1
@@ -136,7 +136,7 @@ abstract class EVMChainWalletBase
136
137 //! Methods to be overridden by every child
138
139 - void addInitialTokens();
139 + void addInitialTokens([bool isMigration]);
140
141 // Future<EVMChainWallet> open({
142 // required String name,
cw_polygon/lib/default_polygon_erc20_tokens.dart
+7
@@ -31,6 +31,13 @@ class DefaultPolygonErc20Tokens {
31 decimal: 6,
32 enabled: true,
33 ),
34 + Erc20Token(
35 + name: "Decentralized Euro",
36 + symbol: "DEURO",
37 + contractAddress: "0xC2ff25dD99e467d2589b2c26EDd270F220F14E47",
38 + decimal: 18,
39 + enabled: true,
40 + ),
41 Erc20Token(
42 name: "Avalanche Token",
43 symbol: "AVAX",
cw_polygon/lib/polygon_wallet.dart
+6 -3
@@ -41,11 +41,14 @@ class PolygonWallet extends EVMChainWallet {
41 }
42
43 @override
44 - void addInitialTokens() {
44 + void addInitialTokens([bool isMigration = false]) {
45 final initialErc20Tokens = DefaultPolygonErc20Tokens().initialPolygonErc20Tokens;
46
47 - for (var token in initialErc20Tokens) {
48 - evmChainErc20TokensBox.put(token.contractAddress, token);
47 + for (final token in initialErc20Tokens) {
48 + if (!evmChainErc20TokensBox.containsKey(token.contractAddress)) {
49 + if (isMigration) token.enabled = false;
50 + evmChainErc20TokensBox.put(token.contractAddress, token);
51 + }
52 }
53 }
54
cw_polygon/lib/polygon_wallet_service.dart
+1
@@ -55,6 +55,7 @@ class PolygonWalletService extends EVMChainWalletService<PolygonWallet> {
55 );
56
57 await wallet.init();
58 + wallet.addInitialTokens(true);
59 await wallet.save();
60 saveBackup(name);
61 return wallet;