mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
feat: Load default ERC20 Tokens for existing ETH and Polygon Wallets (#2274)
This commit is contained in:
parent
bc52cf485e
commit
c12daced40
8 changed files with 24 additions and 9 deletions
|
@ -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 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 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 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 =
|
static final Map<int, CryptoCurrency> _rawCurrencyMap =
|
||||||
[...all, ...havenCurrencies].fold<Map<int, CryptoCurrency>>(<int, CryptoCurrency>{}, (acc, item) {
|
[...all, ...havenCurrencies].fold<Map<int, CryptoCurrency>>(<int, CryptoCurrency>{}, (acc, item) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ class DefaultEthereumErc20Tokens {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
),
|
),
|
||||||
Erc20Token(
|
Erc20Token(
|
||||||
name: "Digital Euro",
|
name: "Decentralized Euro",
|
||||||
symbol: "DEURO",
|
symbol: "DEURO",
|
||||||
contractAddress: "0xbA3f535bbCcCcA2A154b573Ca6c5A49BAAE0a3ea",
|
contractAddress: "0xbA3f535bbCcCcA2A154b573Ca6c5A49BAAE0a3ea",
|
||||||
decimal: 18,
|
decimal: 18,
|
||||||
|
|
|
@ -31,11 +31,14 @@ class EthereumWallet extends EVMChainWallet {
|
||||||
}) : super(nativeCurrency: CryptoCurrency.eth);
|
}) : super(nativeCurrency: CryptoCurrency.eth);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void addInitialTokens() {
|
void addInitialTokens([bool isMigration = false]) {
|
||||||
final initialErc20Tokens = DefaultEthereumErc20Tokens().initialErc20Tokens;
|
final initialErc20Tokens = DefaultEthereumErc20Tokens().initialErc20Tokens;
|
||||||
|
|
||||||
for (var token in initialErc20Tokens) {
|
for (final token in initialErc20Tokens) {
|
||||||
evmChainErc20TokensBox.put(token.contractAddress, token);
|
if (!evmChainErc20TokensBox.containsKey(token.contractAddress)) {
|
||||||
|
if (isMigration) token.enabled = false;
|
||||||
|
evmChainErc20TokensBox.put(token.contractAddress, token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ class EthereumWalletService extends EVMChainWalletService<EthereumWallet> {
|
||||||
);
|
);
|
||||||
|
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
|
wallet.addInitialTokens(true);
|
||||||
await wallet.save();
|
await wallet.save();
|
||||||
saveBackup(name);
|
saveBackup(name);
|
||||||
return wallet;
|
return wallet;
|
||||||
|
|
|
@ -136,7 +136,7 @@ abstract class EVMChainWalletBase
|
||||||
|
|
||||||
//! Methods to be overridden by every child
|
//! Methods to be overridden by every child
|
||||||
|
|
||||||
void addInitialTokens();
|
void addInitialTokens([bool isMigration]);
|
||||||
|
|
||||||
// Future<EVMChainWallet> open({
|
// Future<EVMChainWallet> open({
|
||||||
// required String name,
|
// required String name,
|
||||||
|
|
|
@ -31,6 +31,13 @@ class DefaultPolygonErc20Tokens {
|
||||||
decimal: 6,
|
decimal: 6,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
),
|
),
|
||||||
|
Erc20Token(
|
||||||
|
name: "Decentralized Euro",
|
||||||
|
symbol: "DEURO",
|
||||||
|
contractAddress: "0xC2ff25dD99e467d2589b2c26EDd270F220F14E47",
|
||||||
|
decimal: 18,
|
||||||
|
enabled: true,
|
||||||
|
),
|
||||||
Erc20Token(
|
Erc20Token(
|
||||||
name: "Avalanche Token",
|
name: "Avalanche Token",
|
||||||
symbol: "AVAX",
|
symbol: "AVAX",
|
||||||
|
|
|
@ -41,11 +41,14 @@ class PolygonWallet extends EVMChainWallet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void addInitialTokens() {
|
void addInitialTokens([bool isMigration = false]) {
|
||||||
final initialErc20Tokens = DefaultPolygonErc20Tokens().initialPolygonErc20Tokens;
|
final initialErc20Tokens = DefaultPolygonErc20Tokens().initialPolygonErc20Tokens;
|
||||||
|
|
||||||
for (var token in initialErc20Tokens) {
|
for (final token in initialErc20Tokens) {
|
||||||
evmChainErc20TokensBox.put(token.contractAddress, token);
|
if (!evmChainErc20TokensBox.containsKey(token.contractAddress)) {
|
||||||
|
if (isMigration) token.enabled = false;
|
||||||
|
evmChainErc20TokensBox.put(token.contractAddress, token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ class PolygonWalletService extends EVMChainWalletService<PolygonWallet> {
|
||||||
);
|
);
|
||||||
|
|
||||||
await wallet.init();
|
await wallet.init();
|
||||||
|
wallet.addInitialTokens(true);
|
||||||
await wallet.save();
|
await wallet.save();
|
||||||
saveBackup(name);
|
saveBackup(name);
|
||||||
return wallet;
|
return wallet;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue