Skip to content

Commit

Permalink
moved transaction history
Browse files Browse the repository at this point in the history
  • Loading branch information
Megha-Dev-19 committed Jan 28, 2025
1 parent 60c37ef commit d60421b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const showKYC = props.showKYC;
const accountId = props.accountId;
const displayName = props.displayName ?? true;
const displayImage = props.displayImage ?? true;
const width = props.width ?? null;
const [isVerfied, setIsVerfied] = useState(false);
const [verificationStatus, setVerificationStatus] = useState(null);

Expand Down Expand Up @@ -116,7 +117,7 @@ const HoverCard = () => {
const ReceiverAccountComponent = (
<div
className="d-flex gap-1 align-items-center"
style={{ width: displayImage ? "180px" : "100px" }}
style={{ width: width ? width : displayImage ? "180px" : "100px" }}
>
{displayImage && (
<div style={{ width: "40px", height: 40, position: "relative" }}>
Expand All @@ -130,7 +131,7 @@ const ReceiverAccountComponent = (

<div
className="text-truncate"
style={{ width: displayImage ? "150px" : "100px" }}
style={{ width: width ? width : displayImage ? "150px" : "100px" }}
>
{displayName && <div className="h6 mb-0"> {name}</div>}
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,6 @@ const loading = (
<Widget src={"${REPL_DEVHUB}/widget/devhub.components.molecule.Spinner"} />
);

function sortByDate(items) {
const groupedItems = items ? [...items] : [];

// Sort by timestamp in descending order
const sortedItems = groupedItems.sort((a, b) => {
const timestampA = parseInt(a.timestamp, 10);
const timestampB = parseInt(b.timestamp, 10);

return timestampB - timestampA;
});

return sortedItems;
}

// use BOS open API for gateway and paid for web4
const pikespeakKey = isBosGateway()
? "${REPL_PIKESPEAK_KEY}"
Expand All @@ -66,78 +52,18 @@ function setAPIError() {

useEffect(() => {
if (!showMoreLoading) {
const options = {
method: "GET",
headers: {
"Content-Type": "application/json",
"x-api-key": pikespeakKey,
},
};
const promises = [];
setShowMoreLoading(true);
promises.push(
asyncFetch(
`https://api.pikespeak.ai/account/near-transfer/${treasuryDaoID}?limit=${totalTxnsPerPage}&offset=${
totalTxnsPerPage * (page - 1)
}`,
options
)
);

promises.push(
asyncFetch(
`https://api.pikespeak.ai/account/ft-transfer/${treasuryDaoID}?limit=${totalTxnsPerPage}&offset=${
totalTxnsPerPage * (page - 1)
}`,
options
)
);

if (lockupContract) {
promises.push(
asyncFetch(
`https://api.pikespeak.ai/account/near-transfer/${lockupContract}?limit=${totalTxnsPerPage}&offset=${
totalTxnsPerPage * (page - 1)
}`,
options
)
);

promises.push(
asyncFetch(
`https://api.pikespeak.ai/account/ft-transfer/${lockupContract}?limit=${totalTxnsPerPage}&offset=${
totalTxnsPerPage * (page - 1)
}`,
options
)
);
}
Promise.all(promises).then((i) => {
if (!i[0].ok || !i[1].ok) {
asyncFetch(
`${REPL_BACKEND_API}/transactions-transfer-history?treasuryDaoID=${treasuryDaoID}&lockupContract=${lockupContract}&page=${page}`
).then((res) => {
if (!res.body.data) {
setAPIError();
return;
}
if (lockupContract && (!i[2].ok || !i[3].ok)) {
setAPIError();
return;
}
const nearResp = lockupContract
? i[0]?.body.concat(i[2]?.body)
: i[0]?.body;
const ftResp = lockupContract
? i[1]?.body.concat(i[3]?.body)
: i[1]?.body;
if (Array.isArray(nearResp) && Array.isArray(ftResp)) {
if (
nearResp.length < totalTxnsPerPage &&
ftResp.length < totalTxnsPerPage
) {
} else {
if (res.body.data.length < page * totalTxnsPerPage) {
setHideViewMore(true);
}
setError(null);
setTransactionWithBalance((prev) => {
return [...prev, ...sortByDate(nearResp.concat(ftResp))];
});
setTransactionWithBalance(res.body.data);
setShowMoreLoading(false);
}
});
Expand Down Expand Up @@ -229,6 +155,11 @@ const Container = styled.div`
table {
overflow-x: auto;
}
.account-cell {
min-width: 180px;
max-width: 180px;
}
`;

function formatAccount(text) {
Expand All @@ -252,8 +183,8 @@ return (
<thead>
<tr className="text-secondary px-3 py-3 border-top">
<td>Type</td>
<td>From</td>
<td>To</td>
<td className="account-cell">From</td>
<td className="account-cell">To</td>
<td className="text-right">Transaction</td>
<td className="text-right">Amount</td>
</tr>
Expand Down Expand Up @@ -300,45 +231,33 @@ return (
</div>
</div>
</td>
<td className="fw-semi-bold" style={{ minWidth: 200 }}>
<td className="fw-semi-bold account-cell">
<Widget
src="${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/components.OverlayTrigger"
src={`${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/components.Profile`}
props={{
popup: (
<Widget
src="${REPL_MOB}/widget/Profile.Popover"
props={{ accountId: txn.sender }}
/>
),
children: (
<div className="text-truncate">
{formatAccount(txn.sender)}
</div>
),
accountId: txn.sender,
showKYC: false,
instance,
displayImage: false,
displayName: false,
width: 150,
}}
/>
</td>
<td className="fw-semi-bold" style={{ minWidth: 200 }}>
<td className="fw-semi-bold account-cell">
<Widget
src="${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/components.OverlayTrigger"
src={`${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/components.Profile`}
props={{
popup: (
<Widget
src="${REPL_MOB}/widget/Profile.Popover"
props={{ accountId: txn.receiver }}
/>
),
children: (
<div className="text-truncate">
{formatAccount(txn.receiver)}
</div>
),
accountId: txn.receiver,
showKYC: false,
instance,
displayImage: false,
displayName: false,
width: 150,
}}
/>
</td>
<td className="text-right" style={{ minWidth: 200 }}>
<td className="text-right" style={{ minWidth: 100 }}>
<div className="d-flex gap-2 align-items-center fw-semi-bold justify-content-center">
<a
target="_blank"
Expand Down

0 comments on commit d60421b

Please sign in to comment.