mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
Generic Fixes: Support Errors and others (#1394)
* fix: Crypto amout formatting when calculating fiat amount * fix: Issue with some token symbols coming up with a dollar sign * feat: Split transactions to display on history screen token byh token * fix: Remove restriction on balance length * fix: error when a particular token is not available * fix: Remove token transactions when a token is deleted * fix: Revert previous change * make added spl tokens enabled by default fix issue when entering invalid contract address --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
parent
2ac81250c2
commit
fff77519d9
10 changed files with 54 additions and 40 deletions
|
@ -10,7 +10,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
|
||||||
this.fullName,
|
this.fullName,
|
||||||
this.iconPath,
|
this.iconPath,
|
||||||
this.tag,
|
this.tag,
|
||||||
this.enabled = false,
|
this.enabled = true,
|
||||||
})
|
})
|
||||||
: super(title: title, raw: raw);
|
: super(title: title, raw: raw);
|
||||||
|
|
||||||
|
|
|
@ -234,14 +234,17 @@ abstract class EVMChainClient {
|
||||||
|
|
||||||
final decodedResponse = jsonDecode(response.body)[0] as Map<String, dynamic>;
|
final decodedResponse = jsonDecode(response.body)[0] as Map<String, dynamic>;
|
||||||
|
|
||||||
|
|
||||||
|
final symbol = (decodedResponse['symbol'] ?? '') as String;
|
||||||
|
String filteredSymbol = symbol.replaceFirst(RegExp('^\\\$'), '');
|
||||||
|
|
||||||
final name = decodedResponse['name'] ?? '';
|
final name = decodedResponse['name'] ?? '';
|
||||||
final symbol = decodedResponse['symbol'] ?? '';
|
|
||||||
final decimal = decodedResponse['decimals'] ?? '0';
|
final decimal = decodedResponse['decimals'] ?? '0';
|
||||||
final iconPath = decodedResponse['logo'] ?? '';
|
final iconPath = decodedResponse['logo'] ?? '';
|
||||||
|
|
||||||
return Erc20Token(
|
return Erc20Token(
|
||||||
name: name,
|
name: name,
|
||||||
symbol: symbol,
|
symbol: filteredSymbol,
|
||||||
contractAddress: contractAddress,
|
contractAddress: contractAddress,
|
||||||
decimal: int.tryParse(decimal) ?? 0,
|
decimal: int.tryParse(decimal) ?? 0,
|
||||||
iconPath: iconPath,
|
iconPath: iconPath,
|
||||||
|
|
|
@ -468,9 +468,15 @@ abstract class EVMChainWalletBase
|
||||||
await token.delete();
|
await token.delete();
|
||||||
|
|
||||||
balance.remove(token);
|
balance.remove(token);
|
||||||
|
await _removeTokenTransactionsInHistory(token);
|
||||||
_updateBalance();
|
_updateBalance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _removeTokenTransactionsInHistory(Erc20Token token) async {
|
||||||
|
transactionHistory.transactions.removeWhere((key, value) => value.tokenSymbol == token.title);
|
||||||
|
await transactionHistory.save();
|
||||||
|
}
|
||||||
|
|
||||||
Future<Erc20Token?> getErc20Token(String contractAddress, String chainName) async =>
|
Future<Erc20Token?> getErc20Token(String contractAddress, String chainName) async =>
|
||||||
await _client.getErc20Token(contractAddress, chainName);
|
await _client.getErc20Token(contractAddress, chainName);
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,6 @@ class SolanaTransactionInfo extends TransactionInfo {
|
||||||
String amountFormatted() {
|
String amountFormatted() {
|
||||||
String stringBalance = solAmount.toString();
|
String stringBalance = solAmount.toString();
|
||||||
|
|
||||||
if (stringBalance.toString().length >= 6) {
|
|
||||||
stringBalance = stringBalance.substring(0, 6);
|
|
||||||
}
|
|
||||||
return '$stringBalance $tokenSymbol';
|
return '$stringBalance $tokenSymbol';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -273,32 +273,12 @@ abstract class SolanaWalletBase
|
||||||
|
|
||||||
final transactions = await _client.fetchTransactions(address);
|
final transactions = await _client.fetchTransactions(address);
|
||||||
|
|
||||||
final Map<String, SolanaTransactionInfo> result = {};
|
await _addTransactionsToTransactionHistory(transactions);
|
||||||
|
|
||||||
for (var transactionModel in transactions) {
|
|
||||||
result[transactionModel.id] = SolanaTransactionInfo(
|
|
||||||
id: transactionModel.id,
|
|
||||||
to: transactionModel.to,
|
|
||||||
from: transactionModel.from,
|
|
||||||
blockTime: transactionModel.blockTime,
|
|
||||||
direction: transactionModel.isOutgoingTx
|
|
||||||
? TransactionDirection.outgoing
|
|
||||||
: TransactionDirection.incoming,
|
|
||||||
solAmount: transactionModel.amount,
|
|
||||||
isPending: false,
|
|
||||||
txFee: transactionModel.fee,
|
|
||||||
tokenSymbol: transactionModel.tokenSymbol,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
transactionHistory.addMany(result);
|
|
||||||
|
|
||||||
await transactionHistory.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetches the SPL Tokens transactions linked to the token account Public Key
|
/// Fetches the SPL Tokens transactions linked to the token account Public Key
|
||||||
Future<void> _updateSPLTokenTransactions() async {
|
Future<void> _updateSPLTokenTransactions() async {
|
||||||
List<SolanaTransactionModel> splTokenTransactions = [];
|
// List<SolanaTransactionModel> splTokenTransactions = [];
|
||||||
|
|
||||||
// Make a copy of keys to avoid concurrent modification
|
// Make a copy of keys to avoid concurrent modification
|
||||||
var tokenKeys = List<CryptoCurrency>.from(balance.keys);
|
var tokenKeys = List<CryptoCurrency>.from(balance.keys);
|
||||||
|
@ -312,13 +292,20 @@ abstract class SolanaWalletBase
|
||||||
_walletKeyPair!,
|
_walletKeyPair!,
|
||||||
);
|
);
|
||||||
|
|
||||||
splTokenTransactions.addAll(tokenTxs);
|
// splTokenTransactions.addAll(tokenTxs);
|
||||||
|
await _addTransactionsToTransactionHistory(tokenTxs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// await _addTransactionsToTransactionHistory(splTokenTransactions);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _addTransactionsToTransactionHistory(
|
||||||
|
List<SolanaTransactionModel> transactions,
|
||||||
|
) async {
|
||||||
final Map<String, SolanaTransactionInfo> result = {};
|
final Map<String, SolanaTransactionInfo> result = {};
|
||||||
|
|
||||||
for (var transactionModel in splTokenTransactions) {
|
for (var transactionModel in transactions) {
|
||||||
result[transactionModel.id] = SolanaTransactionInfo(
|
result[transactionModel.id] = SolanaTransactionInfo(
|
||||||
id: transactionModel.id,
|
id: transactionModel.id,
|
||||||
to: transactionModel.to,
|
to: transactionModel.to,
|
||||||
|
@ -460,12 +447,23 @@ abstract class SolanaWalletBase
|
||||||
await token.delete();
|
await token.delete();
|
||||||
|
|
||||||
balance.remove(token);
|
balance.remove(token);
|
||||||
|
await _removeTokenTransactionsInHistory(token);
|
||||||
_updateBalance();
|
_updateBalance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _removeTokenTransactionsInHistory(SPLToken token) async {
|
||||||
|
transactionHistory.transactions.removeWhere((key, value) => value.tokenSymbol == token.title);
|
||||||
|
await transactionHistory.save();
|
||||||
|
}
|
||||||
|
|
||||||
Future<SPLToken?> getSPLToken(String mintAddress) async {
|
Future<SPLToken?> getSPLToken(String mintAddress) async {
|
||||||
// Convert SPL token mint address to public key
|
// Convert SPL token mint address to public key
|
||||||
final mintPublicKey = Ed25519HDPublicKey.fromBase58(mintAddress);
|
final Ed25519HDPublicKey mintPublicKey;
|
||||||
|
try {
|
||||||
|
mintPublicKey = Ed25519HDPublicKey.fromBase58(mintAddress);
|
||||||
|
} catch (_) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch token's metadata account
|
// Fetch token's metadata account
|
||||||
try {
|
try {
|
||||||
|
@ -480,10 +478,12 @@ abstract class SolanaWalletBase
|
||||||
iconPath = await _client.getIconImageFromTokenUri(token.uri);
|
iconPath = await _client.getIconImageFromTokenUri(token.uri);
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
|
||||||
|
String filteredTokenSymbol = token.symbol.replaceFirst(RegExp('^\\\$'), '');
|
||||||
|
|
||||||
return SPLToken.fromMetadata(
|
return SPLToken.fromMetadata(
|
||||||
name: token.name,
|
name: token.name,
|
||||||
mint: token.mint,
|
mint: token.mint,
|
||||||
symbol: token.symbol,
|
symbol: filteredTokenSymbol,
|
||||||
mintAddress: mintAddress,
|
mintAddress: mintAddress,
|
||||||
iconPath: iconPath,
|
iconPath: iconPath,
|
||||||
);
|
);
|
||||||
|
|
|
@ -19,7 +19,7 @@ class SPLToken extends CryptoCurrency with HiveObjectMixin {
|
||||||
@HiveField(3)
|
@HiveField(3)
|
||||||
final int decimal;
|
final int decimal;
|
||||||
|
|
||||||
@HiveField(4, defaultValue: false)
|
@HiveField(4, defaultValue: true)
|
||||||
bool _enabled;
|
bool _enabled;
|
||||||
|
|
||||||
@HiveField(5)
|
@HiveField(5)
|
||||||
|
@ -39,7 +39,7 @@ class SPLToken extends CryptoCurrency with HiveObjectMixin {
|
||||||
required this.mint,
|
required this.mint,
|
||||||
this.iconPath,
|
this.iconPath,
|
||||||
this.tag = 'SOL',
|
this.tag = 'SOL',
|
||||||
bool enabled = false,
|
bool enabled = true,
|
||||||
}) : _enabled = enabled,
|
}) : _enabled = enabled,
|
||||||
super(
|
super(
|
||||||
name: mint.toLowerCase(),
|
name: mint.toLowerCase(),
|
||||||
|
|
|
@ -3,6 +3,8 @@ String calculateFiatAmount({double? price, String? cryptoAmount}) {
|
||||||
return '0.00';
|
return '0.00';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cryptoAmount = cryptoAmount.replaceAll(',', '.');
|
||||||
|
|
||||||
final _amount = double.parse(cryptoAmount);
|
final _amount = double.parse(cryptoAmount);
|
||||||
final _result = price * _amount;
|
final _result = price * _amount;
|
||||||
final result = _result < 0 ? _result * -1 : _result;
|
final result = _result < 0 ? _result * -1 : _result;
|
||||||
|
|
|
@ -142,8 +142,10 @@ class CWEthereum extends Ethereum {
|
||||||
}
|
}
|
||||||
|
|
||||||
wallet as EthereumWallet;
|
wallet as EthereumWallet;
|
||||||
return wallet.erc20Currencies
|
|
||||||
.firstWhere((element) => transaction.tokenSymbol == element.symbol);
|
return wallet.erc20Currencies.firstWhere(
|
||||||
|
(element) => transaction.tokenSymbol == element.symbol,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -140,8 +140,10 @@ class CWPolygon extends Polygon {
|
||||||
}
|
}
|
||||||
|
|
||||||
wallet as PolygonWallet;
|
wallet as PolygonWallet;
|
||||||
|
|
||||||
return wallet.erc20Currencies.firstWhere(
|
return wallet.erc20Currencies.firstWhere(
|
||||||
(element) => transaction.tokenSymbol.toLowerCase() == element.symbol.toLowerCase());
|
(element) => transaction.tokenSymbol.toLowerCase() == element.symbol.toLowerCase(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -110,8 +110,10 @@ class CWSolana extends Solana {
|
||||||
}
|
}
|
||||||
|
|
||||||
wallet as SolanaWallet;
|
wallet as SolanaWallet;
|
||||||
return wallet.splTokenCurrencies
|
|
||||||
.firstWhere((element) => transaction.tokenSymbol == element.symbol);
|
return wallet.splTokenCurrencies.firstWhere(
|
||||||
|
(element) => transaction.tokenSymbol == element.symbol,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
Loading…
Reference in a new issue