Skip to content

Commit

Permalink
Merge pull request #2797 from superhero-com/feature/show-pending-tran…
Browse files Browse the repository at this point in the history
…scations

fix(aeternity): show pending and tip withdrawn transactions
  • Loading branch information
CedrikNikita authored Mar 6, 2024
2 parents 37b5f0a + f3b7c20 commit 94f6e0d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
20 changes: 16 additions & 4 deletions src/composables/latestTransactionList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,28 @@ 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)
if (currentNetworkName !== activeNetwork.value.name) {
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));
Expand Down Expand Up @@ -117,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
Expand Down
40 changes: 31 additions & 9 deletions src/composables/transactionList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export function useTransactionList({
const {
paginationParams,
regularTransactions,
pendingTransactions,
tipWithdrawnTransactions,
} = await fetchTransactions(state.value.nextPagePaginationParams);

if (accountAddress !== state.value.accountAddress
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions src/protocols/aeternity/libs/AeternityAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ export class AeternityAdapter extends BaseProtocolAdapter {
...transaction,
pending: true,
protocol: PROTOCOLS.aeternity,
microTime: Date.now(),
transactionOwner: address,
}));
} catch (error) {
return [];
Expand Down Expand Up @@ -350,6 +352,7 @@ export class AeternityAdapter extends BaseProtocolAdapter {
blockHeight: height,
claim: true,
protocol: PROTOCOLS.aeternity,
transactionOwner: address,
}));

return tipWithdrawnTransactions;
Expand Down

0 comments on commit 94f6e0d

Please sign in to comment.