Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Redesign] Display empty Tx history when we receive non-200 response from respective APIs #2692

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading