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:
Adegoke David 2024-04-25 02:14:53 +01:00 committed by GitHub
parent 2ac81250c2
commit fff77519d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 54 additions and 40 deletions

View file

@ -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';
}

View file

@ -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,
);

View file

@ -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(),