show only token transfers in token tx history (for now)

This commit is contained in:
julian 2023-03-27 08:43:35 -06:00
parent 4bd87e8dce
commit 6612dde2ef
2 changed files with 66 additions and 74 deletions

View file

@ -387,15 +387,14 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
final List<Tuple2<Transaction, Address?>> txnsData = []; final List<Tuple2<Transaction, Address?>> txnsData = [];
for (final tuple in data) { for (final tuple in data) {
int amount; // ignore all non Transfer events (for now)
if (tuple.item1.topics[0] == kTransferEventSignature) {
final Amount amount;
String fromAddress, toAddress; String fromAddress, toAddress;
if (tuple.item1.articulatedLog == null) { amount = Amount(
if (tuple.item1.topics.length != 3) { rawValue: tuple.item1.data.toBigIntFromHex,
throw Exception("Topics length != 3 for " fractionDigits: tokenContract.decimals,
"${ethWallet.walletName} ${ethWallet.walletId}: " );
"${tuple.item1.toString()}");
}
amount = tuple.item1.data.toBigIntFromHex.toInt();
fromAddress = _addressFromTopic( fromAddress = _addressFromTopic(
tuple.item1.topics[1], tuple.item1.topics[1],
@ -403,17 +402,6 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
toAddress = _addressFromTopic( toAddress = _addressFromTopic(
tuple.item1.topics[2], tuple.item1.topics[2],
); );
} else {
amount = int.parse(
tuple.item1.articulatedLog!.inputs.amount,
);
fromAddress = checksumEthereumAddress(
tuple.item1.articulatedLog!.inputs.from,
);
toAddress = checksumEthereumAddress(
tuple.item1.articulatedLog!.inputs.to,
);
}
bool isIncoming; bool isIncoming;
bool isSentToSelf = false; bool isSentToSelf = false;
@ -434,14 +422,12 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
walletId: ethWallet.walletId, walletId: ethWallet.walletId,
txid: tuple.item1.transactionHash, txid: tuple.item1.transactionHash,
timestamp: tuple.item2.timestamp, timestamp: tuple.item2.timestamp,
type: isIncoming ? TransactionType.incoming : TransactionType.outgoing, type:
isIncoming ? TransactionType.incoming : TransactionType.outgoing,
subType: TransactionSubType.ethToken, subType: TransactionSubType.ethToken,
amount: amount, amount: amount.raw.toInt(),
amountString: Amount( amountString: amount.toJsonString(),
rawValue: BigInt.from(amount), fee: (tuple.item2.gasUsed.raw * tuple.item2.gasPrice.raw).toInt(),
fractionDigits: tokenContract.decimals,
).toJsonString(),
fee: tuple.item2.gasUsed * tuple.item2.gasPrice.toInt(),
height: tuple.item1.blockNumber, height: tuple.item1.blockNumber,
isCancelled: false, isCancelled: false,
isLelantus: false, isLelantus: false,
@ -466,12 +452,14 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
? (DerivationPath()..value = "$hdPathEthereum/0") ? (DerivationPath()..value = "$hdPathEthereum/0")
: null, : null,
type: AddressType.ethereum, type: AddressType.ethereum,
subType: subType: isSentToSelf
isSentToSelf ? AddressSubType.receiving : AddressSubType.nonWallet, ? AddressSubType.receiving
: AddressSubType.nonWallet,
); );
txnsData.add(Tuple2(txn, transactionAddress)); txnsData.add(Tuple2(txn, transactionAddress));
} }
}
await ethWallet.db.addNewTransactionData(txnsData, ethWallet.walletId); await ethWallet.db.addNewTransactionData(txnsData, ethWallet.walletId);
// quick hack to notify manager to call notifyListeners if // quick hack to notify manager to call notifyListeners if

View file

@ -56,6 +56,10 @@ class GasTracker {
const hdPathEthereum = "m/44'/60'/0'/0"; const hdPathEthereum = "m/44'/60'/0'/0";
// equal to "0x${keccak256("Transfer(address,address,uint256)".toUint8ListFromUtf8).toHex}";
const kTransferEventSignature =
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
String getPrivateKey(String mnemonic, String mnemonicPassphrase) { String getPrivateKey(String mnemonic, String mnemonicPassphrase) {
final isValidMnemonic = bip39.validateMnemonic(mnemonic); final isValidMnemonic = bip39.validateMnemonic(mnemonic);
if (!isValidMnemonic) { if (!isValidMnemonic) {