Skip to content

Commit

Permalink
Add getTxId Interface conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
lq0-github committed Feb 19, 2024
1 parent 139635b commit 65257f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
4 changes: 4 additions & 0 deletions data/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class DataSource {
config?.liquidationUrl,
);
}

getTxId(receipt_id) {
return this.callAPI(`/v1/search/?keyword=${receipt_id}`, "GET", null, null, config?.txIdApiUrl);
}
}

export default DataSource;
26 changes: 15 additions & 11 deletions screens/Dashboard/records.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Records = ({ isShow }) => {
const { toastMessage, showToast } = useToastMessage();
const assets = useAppSelector(getAssets);
const [isLoading, setIsLoading] = useState(false);
const [docs, setDocs] = useState([]);
const [docs, setDocs] = useState<any>([]);
const [pagination, setPagination] = useState<{
page?: number;
totalPages?: number;
Expand All @@ -37,7 +37,7 @@ const Records = ({ isShow }) => {
try {
setIsLoading(true);
const response = await Datasource.shared.getRecords(accountId, page, 10);
const list = response?.record_list?.map((d) => {
const list = response?.record_list?.map(async (d) => {
let tokenId = d.token_id;
if (nearNativeTokens.includes(tokenId)) {
tokenId = nearTokenId;
Expand All @@ -46,9 +46,13 @@ const Records = ({ isShow }) => {
const cloned = { ...d.data };
cloned.metadata = standardizeAsset({ ...cloned.metadata });
d.data = cloned;
return d;
const txidResponse = await Datasource.shared.getTxId(d.receipt_id);
const txid = txidResponse?.receipts[0]?.originated_from_transaction_hash;

return { ...d, txid };
});
setDocs(list);
const resolvedList = await Promise.all(list);
setDocs(resolvedList);
setPagination((d) => {
return {
...d,
Expand All @@ -63,8 +67,8 @@ const Records = ({ isShow }) => {
}
};

const handleTxClick = (tx) => {
window.open(`https://nearblocks.io/txns/${tx}`);
const handleTxClick = (txid) => {
window.open(`https://nearblocks.io/txns/${txid}`);
};

const columns = getColumns({ showToast, handleTxClick });
Expand Down Expand Up @@ -129,20 +133,20 @@ const getColumns = ({ showToast, handleTxClick }) => [
{
header: () => <div className="text-right">View in NEAR explorer</div>,
cell: ({ originalData }) => {
const { tx_id } = originalData || {};
if (!tx_id) {
const { receipt_id, txid } = originalData || {};
if (!receipt_id) {
return null;
}
return (
<div className="flex items-center gap-2 justify-end">
<div
className="text-gray-300 text-right cursor-pointer hover:underline transform hover:opacity-80"
onClick={() => handleTxClick(tx_id)}
onClick={() => handleTxClick(txid)}
>
{maskMiddleString(tx_id, 4, 34)}
{maskMiddleString(txid, 4, 34)}
</div>

<CopyToClipboard text={tx_id} onCopy={() => showToast("Copied")}>
<CopyToClipboard text={txid} onCopy={() => showToast("Copied")}>
<div className="cursor-pointer">
<CopyIcon />
</div>
Expand Down
2 changes: 2 additions & 0 deletions utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const getConfig = (env: string = defaultNetwork) => {
explorerUrl: "https://explorer.mainnet.near.org",
liquidationUrl: "https://api.data-service.burrow.finance",
recordsUrl: "https://indexer.ref.finance",
txIdApiUrl: "https://api2.nearblocks.io",
SPECIAL_REGISTRATION_TOKEN_IDS: [
"17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
],
Expand All @@ -56,6 +57,7 @@ const getConfig = (env: string = defaultNetwork) => {
explorerUrl: "https://explorer.testnet.near.org",
liquidationUrl: "https://dev.data-service.ref-finance.com",
recordsUrl: "https://dev-indexer.ref-finance.com",
txIdApiUrl: "https://api-testnet.nearblocks.io",
SPECIAL_REGISTRATION_TOKEN_IDS: [
"3e2210e1184b45b64c8a434c0a7e7b23cc04ea7eb7a6c3c32520d03d4afcb8af",
],
Expand Down

0 comments on commit 65257f1

Please sign in to comment.