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

This commit is contained in:
Konstantin Ullrich 2025-05-15 21:57:02 +02:00 committed by GitHub
parent bc52cf485e
commit c12daced40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 24 additions and 9 deletions

View file

@ -232,7 +232,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
static const ton = CryptoCurrency(title: 'TON', fullName: 'Toncoin', raw: 95, name: 'ton', iconPath: 'assets/images/ton_icon.png', decimals: 8);
static const zano = CryptoCurrency(title: 'ZANO', tag: 'ZANO', fullName: 'Zano', raw: 96, name: 'zano', iconPath: 'assets/images/zano_icon.png', decimals: 12);
static const flip = CryptoCurrency(title: 'FLIP', tag: 'ETH', fullName: 'Chainflip', raw: 97, name: 'flip', iconPath: 'assets/images/flip_icon.png', decimals: 18);
static const deuro = CryptoCurrency(title: 'DEURO', tag: 'ETH', fullName: 'Digital Euro', raw: 98, name: 'deuro', iconPath: 'assets/images/deuro_icon.png', decimals: 18);
static const deuro = CryptoCurrency(title: 'DEURO', tag: 'ETH', fullName: 'Decentralized Euro', raw: 98, name: 'deuro', iconPath: 'assets/images/deuro_icon.png', decimals: 18);
static final Map<int, CryptoCurrency> _rawCurrencyMap =
[...all, ...havenCurrencies].fold<Map<int, CryptoCurrency>>(<int, CryptoCurrency>{}, (acc, item) {

View file

@ -18,7 +18,7 @@ class DefaultEthereumErc20Tokens {
enabled: true,
),
Erc20Token(
name: "Digital Euro",
name: "Decentralized Euro",
symbol: "DEURO",
contractAddress: "0xbA3f535bbCcCcA2A154b573Ca6c5A49BAAE0a3ea",
decimal: 18,

View file

@ -31,11 +31,14 @@ class EthereumWallet extends EVMChainWallet {
}) : super(nativeCurrency: CryptoCurrency.eth);
@override
void addInitialTokens() {
void addInitialTokens([bool isMigration = false]) {
final initialErc20Tokens = DefaultEthereumErc20Tokens().initialErc20Tokens;
for (var token in initialErc20Tokens) {
evmChainErc20TokensBox.put(token.contractAddress, token);
for (final token in initialErc20Tokens) {
if (!evmChainErc20TokensBox.containsKey(token.contractAddress)) {
if (isMigration) token.enabled = false;
evmChainErc20TokensBox.put(token.contractAddress, token);
}
}
}

View file

@ -53,6 +53,7 @@ class EthereumWalletService extends EVMChainWalletService<EthereumWallet> {
);
await wallet.init();
wallet.addInitialTokens(true);
await wallet.save();
saveBackup(name);
return wallet;

View file

@ -136,7 +136,7 @@ abstract class EVMChainWalletBase
//! Methods to be overridden by every child
void addInitialTokens();
void addInitialTokens([bool isMigration]);
// Future<EVMChainWallet> open({
// required String name,

View file

@ -31,6 +31,13 @@ class DefaultPolygonErc20Tokens {
decimal: 6,
enabled: true,
),
Erc20Token(
name: "Decentralized Euro",
symbol: "DEURO",
contractAddress: "0xC2ff25dD99e467d2589b2c26EDd270F220F14E47",
decimal: 18,
enabled: true,
),
Erc20Token(
name: "Avalanche Token",
symbol: "AVAX",

View file

@ -41,11 +41,14 @@ class PolygonWallet extends EVMChainWallet {
}
@override
void addInitialTokens() {
void addInitialTokens([bool isMigration = false]) {
final initialErc20Tokens = DefaultPolygonErc20Tokens().initialPolygonErc20Tokens;
for (var token in initialErc20Tokens) {
evmChainErc20TokensBox.put(token.contractAddress, token);
for (final token in initialErc20Tokens) {
if (!evmChainErc20TokensBox.containsKey(token.contractAddress)) {
if (isMigration) token.enabled = false;
evmChainErc20TokensBox.put(token.contractAddress, token);
}
}
}

View file

@ -55,6 +55,7 @@ class PolygonWalletService extends EVMChainWalletService<PolygonWallet> {
);
await wallet.init();
wallet.addInitialTokens(true);
await wallet.save();
saveBackup(name);
return wallet;