diff --git a/.changelog/1979.internal.md b/.changelog/1979.internal.md new file mode 100644 index 0000000000..4b58f50302 --- /dev/null +++ b/.changelog/1979.internal.md @@ -0,0 +1 @@ +Add transaction detail API cache diff --git a/src/vendors/oasisscan.ts b/src/vendors/oasisscan.ts index bcc6cbc73c..e38c60f143 100644 --- a/src/vendors/oasisscan.ts +++ b/src/vendors/oasisscan.ts @@ -22,6 +22,8 @@ import { import { throwAPIErrors } from './helpers' +const getTransactionCacheMap: Record = {} + export function getOasisscanAPIs(url: string | 'https://api.oasisscan.com/mainnet') { const explorerConfig = new Configuration({ basePath: url, @@ -54,11 +56,20 @@ export function getOasisscanAPIs(url: string | 'https://api.oasisscan.com/mainne } async function getTransaction({ hash }: { hash: string }) { + if (hash in getTransactionCacheMap) { + return getTransactionCacheMap[hash] + } + const transaction = await operationsEntity.getTransaction({ hash, }) - const [parsedTx] = parseTransactionsList([transaction.data]) + const [parsedTx] = parseTransactionsList([transaction.data ?? {}]) + + if (transaction.code === 0 && !!transaction.data) { + getTransactionCacheMap[hash] = parsedTx + } + return parsedTx }