mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 11:39: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.iconPath,
|
||||
this.tag,
|
||||
this.enabled = false,
|
||||
this.enabled = true,
|
||||
})
|
||||
: super(title: title, raw: raw);
|
||||
|
||||
|
|
|
@ -234,14 +234,17 @@ abstract class EVMChainClient {
|
|||
|
||||
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 symbol = decodedResponse['symbol'] ?? '';
|
||||
final decimal = decodedResponse['decimals'] ?? '0';
|
||||
final iconPath = decodedResponse['logo'] ?? '';
|
||||
|
||||
return Erc20Token(
|
||||
name: name,
|
||||
symbol: symbol,
|
||||
symbol: filteredSymbol,
|
||||
contractAddress: contractAddress,
|
||||
decimal: int.tryParse(decimal) ?? 0,
|
||||
iconPath: iconPath,
|
||||
|
|
|
@ -468,9 +468,15 @@ abstract class EVMChainWalletBase
|
|||
await token.delete();
|
||||
|
||||
balance.remove(token);
|
||||
await _removeTokenTransactionsInHistory(token);
|
||||
_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 =>
|
||||
await _client.getErc20Token(contractAddress, chainName);
|
||||
|
||||
|
|
|
@ -34,10 +34,7 @@ class SolanaTransactionInfo extends TransactionInfo {
|
|||
@override
|
||||
String amountFormatted() {
|
||||
String stringBalance = solAmount.toString();
|
||||
|
||||
if (stringBalance.toString().length >= 6) {
|
||||
stringBalance = stringBalance.substring(0, 6);
|
||||
}
|
||||
|
||||
return '$stringBalance $tokenSymbol';
|
||||
}
|
||||
|
||||
|
|
|
@ -273,32 +273,12 @@ abstract class SolanaWalletBase
|
|||
|
||||
final transactions = await _client.fetchTransactions(address);
|
||||
|
||||
final Map<String, SolanaTransactionInfo> result = {};
|
||||
|
||||
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();
|
||||
await _addTransactionsToTransactionHistory(transactions);
|
||||
}
|
||||
|
||||
/// Fetches the SPL Tokens transactions linked to the token account Public Key
|
||||
Future<void> _updateSPLTokenTransactions() async {
|
||||
List<SolanaTransactionModel> splTokenTransactions = [];
|
||||
// List<SolanaTransactionModel> splTokenTransactions = [];
|
||||
|
||||
// Make a copy of keys to avoid concurrent modification
|
||||
var tokenKeys = List<CryptoCurrency>.from(balance.keys);
|
||||
|
@ -312,13 +292,20 @@ abstract class SolanaWalletBase
|
|||
_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 = {};
|
||||
|
||||
for (var transactionModel in splTokenTransactions) {
|
||||
for (var transactionModel in transactions) {
|
||||
result[transactionModel.id] = SolanaTransactionInfo(
|
||||
id: transactionModel.id,
|
||||
to: transactionModel.to,
|
||||
|
@ -460,12 +447,23 @@ abstract class SolanaWalletBase
|
|||
await token.delete();
|
||||
|
||||
balance.remove(token);
|
||||
await _removeTokenTransactionsInHistory(token);
|
||||
_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 {
|
||||
// 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
|
||||
try {
|
||||
|
@ -480,10 +478,12 @@ abstract class SolanaWalletBase
|
|||
iconPath = await _client.getIconImageFromTokenUri(token.uri);
|
||||
} catch (_) {}
|
||||
|
||||
String filteredTokenSymbol = token.symbol.replaceFirst(RegExp('^\\\$'), '');
|
||||
|
||||
return SPLToken.fromMetadata(
|
||||
name: token.name,
|
||||
mint: token.mint,
|
||||
symbol: token.symbol,
|
||||
symbol: filteredTokenSymbol,
|
||||
mintAddress: mintAddress,
|
||||
iconPath: iconPath,
|
||||
);
|
||||
|
|
|
@ -19,7 +19,7 @@ class SPLToken extends CryptoCurrency with HiveObjectMixin {
|
|||
@HiveField(3)
|
||||
final int decimal;
|
||||
|
||||
@HiveField(4, defaultValue: false)
|
||||
@HiveField(4, defaultValue: true)
|
||||
bool _enabled;
|
||||
|
||||
@HiveField(5)
|
||||
|
@ -39,7 +39,7 @@ class SPLToken extends CryptoCurrency with HiveObjectMixin {
|
|||
required this.mint,
|
||||
this.iconPath,
|
||||
this.tag = 'SOL',
|
||||
bool enabled = false,
|
||||
bool enabled = true,
|
||||
}) : _enabled = enabled,
|
||||
super(
|
||||
name: mint.toLowerCase(),
|
||||
|
|
|
@ -3,6 +3,8 @@ String calculateFiatAmount({double? price, String? cryptoAmount}) {
|
|||
return '0.00';
|
||||
}
|
||||
|
||||
cryptoAmount = cryptoAmount.replaceAll(',', '.');
|
||||
|
||||
final _amount = double.parse(cryptoAmount);
|
||||
final _result = price * _amount;
|
||||
final result = _result < 0 ? _result * -1 : _result;
|
||||
|
|
|
@ -142,8 +142,10 @@ class CWEthereum extends Ethereum {
|
|||
}
|
||||
|
||||
wallet as EthereumWallet;
|
||||
return wallet.erc20Currencies
|
||||
.firstWhere((element) => transaction.tokenSymbol == element.symbol);
|
||||
|
||||
return wallet.erc20Currencies.firstWhere(
|
||||
(element) => transaction.tokenSymbol == element.symbol,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -140,8 +140,10 @@ class CWPolygon extends Polygon {
|
|||
}
|
||||
|
||||
wallet as PolygonWallet;
|
||||
|
||||
return wallet.erc20Currencies.firstWhere(
|
||||
(element) => transaction.tokenSymbol.toLowerCase() == element.symbol.toLowerCase());
|
||||
(element) => transaction.tokenSymbol.toLowerCase() == element.symbol.toLowerCase(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -110,8 +110,10 @@ class CWSolana extends Solana {
|
|||
}
|
||||
|
||||
wallet as SolanaWallet;
|
||||
return wallet.splTokenCurrencies
|
||||
.firstWhere((element) => transaction.tokenSymbol == element.symbol);
|
||||
|
||||
return wallet.splTokenCurrencies.firstWhere(
|
||||
(element) => transaction.tokenSymbol == element.symbol,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
Loading…
Reference in a new issue