Skip to content

Commit

Permalink
[Redesign] Display empty Tx history when we receive non-200 response …
Browse files Browse the repository at this point in the history
…from respective APIs

Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz>
  • Loading branch information
emreboga committed Sep 23, 2024
1 parent 418068b commit 483631a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 61 deletions.
68 changes: 37 additions & 31 deletions wormhole-connect/src/hooks/useTransactionHistoryMayan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,37 +130,43 @@ const useTransactionHistoryMayan = (
`${config.mayanApi}/v3/swaps?trader=${address}&offset=${offset}&limit=${limit}`,
);

const resPayload = await res.json();

if (!cancelled) {
const resData = resPayload?.data;

if (resData?.length > 0) {
setTransactions((txs) => {
const parsedTxs = parseTransactions(resData);

if (txs && txs.length > 0) {
// We need to keep track of existing tx hashes to prevent duplicates in the final list
const existingTxs = new Set<string>();
txs.forEach((tx: Transaction) => {
if (tx?.txHash) {
existingTxs.add(tx.txHash);
}
});

// Add the new set transactions while filtering out duplicates
return txs.concat(
parsedTxs.filter(
(tx: Transaction) => !existingTxs.has(tx.txHash),
),
);
}
return parsedTxs;
});
}

if (resData?.length < limit) {
setHasMore(false);
// If the fetch was unsuccessful, return an empty set
if (res.status !== 200) {
setIsFetching(false);
setTransactions([]);
} else {
const resPayload = await res.json();

if (!cancelled) {
const resData = resPayload?.data;

if (resData) {
setTransactions((txs) => {
const parsedTxs = parseTransactions(resData);

if (txs && txs.length > 0) {
// We need to keep track of existing tx hashes to prevent duplicates in the final list
const existingTxs = new Set<string>();
txs.forEach((tx: Transaction) => {
if (tx?.txHash) {
existingTxs.add(tx.txHash);
}
});

// Add the new set transactions while filtering out duplicates
return txs.concat(
parsedTxs.filter(
(tx: Transaction) => !existingTxs.has(tx.txHash),
),
);
}
return parsedTxs;
});
}

if (resData?.length < limit) {
setHasMore(false);
}
}
}
} catch (error) {
Expand Down
62 changes: 34 additions & 28 deletions wormhole-connect/src/hooks/useTransactionHistoryWHScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,35 +252,41 @@ const useTransactionHistoryWHScan = (
{ headers },
);

const resPayload = await res.json();

if (!cancelled) {
const resData = resPayload?.operations;
if (resData.length > 0) {
setTransactions((txs) => {
const parsedTxs = parseTransactions(resData);
if (txs && txs.length > 0) {
// We need to keep track of existing tx hashes to prevent duplicates in the final list
const existingTxs = new Set<string>();
txs.forEach((tx: Transaction) => {
if (tx?.txHash) {
existingTxs.add(tx.txHash);
}
});

// Add the new set transactions while filtering out duplicates
return txs.concat(
parsedTxs.filter(
(tx: Transaction) => !existingTxs.has(tx.txHash),
),
);
}
return parsedTxs;
});
}
// If the fetch was unsuccessful, return an empty set
if (res.status !== 200) {
setIsFetching(false);
setTransactions([]);
} else {
const resPayload = await res.json();

if (!cancelled) {
const resData = resPayload?.operations;
if (resData) {
setTransactions((txs) => {
const parsedTxs = parseTransactions(resData);
if (txs && txs.length > 0) {
// We need to keep track of existing tx hashes to prevent duplicates in the final list
const existingTxs = new Set<string>();
txs.forEach((tx: Transaction) => {
if (tx?.txHash) {
existingTxs.add(tx.txHash);
}
});

// Add the new set transactions while filtering out duplicates
return txs.concat(
parsedTxs.filter(
(tx: Transaction) => !existingTxs.has(tx.txHash),
),
);
}
return parsedTxs;
});
}

if (resData?.length < pageSize) {
setHasMore(false);
if (resData?.length < pageSize) {
setHasMore(false);
}
}
}
} catch (error) {
Expand Down
7 changes: 5 additions & 2 deletions wormhole-connect/src/views/v2/TxHistory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import config from 'config';
import PoweredByIcon from 'icons/PoweredBy';
import useTransactionHistory from 'hooks/useTransactionHistory';
import { setRoute as setAppRoute } from 'store/router';
import { trimAddress } from 'utils';
import { joinClass } from 'utils/style';
import TxHistoryItem from 'views/v2/TxHistory/Item';

Expand Down Expand Up @@ -117,8 +118,10 @@ const TxHistory = () => {
return <></>;
} else if (transactions.length === 0) {
return (
<Typography textAlign="center">
No transactions found for the address {sendingWallet.address}
<Typography color={theme.palette.text.secondary} textAlign="center">
{`No transactions found for the wallet ${trimAddress(
sendingWallet.address,
)}`}
</Typography>
);
}
Expand Down

0 comments on commit 483631a

Please sign in to comment.