From d1668179408ab96e3eb8067ba74ccfcbea98c357 Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 5 Mar 2024 15:23:24 +0400 Subject: [PATCH 1/2] fix(aeternity): show pending and tip withdrawn transactions --- src/composables/latestTransactionList.ts | 18 +++++++-- src/composables/transactionList.ts | 40 ++++++++++++++----- .../aeternity/libs/AeternityAdapter.ts | 3 ++ 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/composables/latestTransactionList.ts b/src/composables/latestTransactionList.ts index baf1a258a..5dd8c6b1f 100644 --- a/src/composables/latestTransactionList.ts +++ b/src/composables/latestTransactionList.ts @@ -76,7 +76,11 @@ export function useLatestTransactionList() { async function loadAccountLatestTransactions({ address, protocol }: IAccount) { const adapter = ProtocolAdapterFactory.getAdapter(protocol); const currentNetworkName = activeNetwork.value.name; - const { regularTransactions } = await adapter.fetchAccountTransactions(address); + const { + regularTransactions, + pendingTransactions, + tipWithdrawnTransactions, + } = await adapter.fetchAccountTransactions(address); // This is necessary in case the user switches between networks faster, // than transactions are returned (limitations of the free Ethereum middleware) @@ -84,8 +88,16 @@ export function useLatestTransactionList() { return true; } - if (regularTransactions.length) { - accountsTransactionsLatest.value[address] = regularTransactions; + if ( + regularTransactions.length + || pendingTransactions?.length + || tipWithdrawnTransactions?.length + ) { + accountsTransactionsLatest.value[address] = [ + ...regularTransactions, + ...(pendingTransactions || []), + ...(tipWithdrawnTransactions || []), + ]; if (accountsTransactionsPending.value[address]?.length) { regularTransactions.forEach(({ hash }) => removeAccountPendingTransaction(address, hash)); diff --git a/src/composables/transactionList.ts b/src/composables/transactionList.ts index 092e39183..af8a5cd0e 100644 --- a/src/composables/transactionList.ts +++ b/src/composables/transactionList.ts @@ -106,6 +106,8 @@ export function useTransactionList({ const { paginationParams, regularTransactions, + pendingTransactions, + tipWithdrawnTransactions, } = await fetchTransactions(state.value.nextPagePaginationParams); if (accountAddress !== state.value.accountAddress @@ -120,12 +122,20 @@ export function useTransactionList({ state.value.isEndReached = true; } - if (regularTransactions?.length) { - if (state.value.isInitialLoadDone) { - state.value.transactionsLoaded = uniqBy([...state.value.transactionsLoaded, ...regularTransactions], 'hash'); - } else { - state.value.transactionsLoaded = regularTransactions; - } + if ( + regularTransactions?.length + || pendingTransactions?.length + || tipWithdrawnTransactions?.length + ) { + state.value.transactionsLoaded = uniqBy( + [ + ...(state.value.isInitialLoadDone ? state.value.transactionsLoaded : []), + ...regularTransactions, + ...(pendingTransactions || []), + ...(tipWithdrawnTransactions || []), + ], + 'hash', + ); } isLoading.value = false; @@ -146,7 +156,12 @@ export function useTransactionList({ pollingIntervalId = setInterval(async () => { if (isAppActive.value) { - const { paginationParams, regularTransactions } = await fetchTransactions(); + const { + paginationParams, + regularTransactions, + pendingTransactions, + tipWithdrawnTransactions, + } = await fetchTransactions(); if (accountAddress !== state.value.accountAddress || assetContractId !== state.value.assetContractId @@ -156,13 +171,20 @@ export function useTransactionList({ return; } + const filteredLoadedTransactions = (state.value.transactionsLoaded as any) + .filter(({ claim = false, pending = false }) => !claim && !pending); + // If newly fetched first transaction is different than the first transaction stored // it means that the list and the pagination params needs to be reset. if ( regularTransactions?.length - && regularTransactions?.[0]?.hash !== state.value.transactionsLoaded?.[0]?.hash + && regularTransactions?.[0]?.hash !== filteredLoadedTransactions?.[0]?.hash ) { - state.value.transactionsLoaded = regularTransactions; + state.value.transactionsLoaded = [ + ...regularTransactions, + ...(pendingTransactions || []), + ...(tipWithdrawnTransactions || []), + ]; state.value.nextPagePaginationParams = paginationParams; state.value.isEndReached = false; } diff --git a/src/protocols/aeternity/libs/AeternityAdapter.ts b/src/protocols/aeternity/libs/AeternityAdapter.ts index e26edfa10..fcd478200 100644 --- a/src/protocols/aeternity/libs/AeternityAdapter.ts +++ b/src/protocols/aeternity/libs/AeternityAdapter.ts @@ -304,6 +304,8 @@ export class AeternityAdapter extends BaseProtocolAdapter { ...transaction, pending: true, protocol: PROTOCOLS.aeternity, + microTime: Date.now(), + transactionOwner: address, })); } catch (error) { return []; @@ -344,6 +346,7 @@ export class AeternityAdapter extends BaseProtocolAdapter { blockHeight: height, claim: true, protocol: PROTOCOLS.aeternity, + transactionOwner: address, })); return tipWithdrawnTransactions; From f3b7c20a817dc162682ae76ae2efb770aedd419b Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 6 Mar 2024 14:43:50 +0400 Subject: [PATCH 2/2] fix: remove custom pending transactions correctly --- src/composables/latestTransactionList.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/composables/latestTransactionList.ts b/src/composables/latestTransactionList.ts index 5dd8c6b1f..0544584c6 100644 --- a/src/composables/latestTransactionList.ts +++ b/src/composables/latestTransactionList.ts @@ -129,7 +129,7 @@ export function useLatestTransactionList() { if (!accountsTransactionsPending.value[address]) { accountsTransactionsPending.value[address] = []; } - accountsTransactionsPending.value[address].push(transaction); + accountsTransactionsPending.value[address].push({ ...transaction, microTime: Date.now() }); try { await ProtocolAdapterFactory