-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'confirm-following-staking-banner' of github.com:dfinity…
…/nns-dapp into confirm-following-staking-banner
- Loading branch information
Showing
10 changed files
with
362 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { getTransactions } from "$lib/api/icp-index.api"; | ||
import { type SignIdentity } from "@dfinity/agent"; | ||
import type { TransactionWithId } from "@dfinity/ledger-icp"; | ||
import { isNullish } from "@dfinity/utils"; | ||
|
||
export const getAllTransactionsFromAccountAndIdentity = async ({ | ||
accountId, | ||
identity, | ||
lastTransactionId = undefined, | ||
allTransactions = [], | ||
currentPageIndex = 1, | ||
}: { | ||
accountId: string; | ||
identity: SignIdentity; | ||
lastTransactionId?: bigint; | ||
allTransactions?: TransactionWithId[]; | ||
currentPageIndex?: number; | ||
}): Promise<TransactionWithId[] | undefined> => { | ||
const pageSize = 100n; | ||
const maxNumberOfPages = 10; | ||
|
||
try { | ||
// TODO: Decide what to do if we reach the maximum number of iterations. | ||
if (currentPageIndex > maxNumberOfPages) { | ||
console.warn( | ||
`Reached maximum limit of iterations(${maxNumberOfPages}). Stopping.` | ||
); | ||
return allTransactions; | ||
} | ||
|
||
const { transactions, oldestTxId } = await getTransactions({ | ||
accountIdentifier: accountId, | ||
identity, | ||
maxResults: pageSize, | ||
start: lastTransactionId, | ||
}); | ||
|
||
const updatedTransactions = [...allTransactions, ...transactions]; | ||
|
||
// We consider it complete if we find the oldestTxId in the list of transactions or if oldestTxId is null. | ||
// The latter condition is necessary if the list of transactions is empty, which would otherwise return false. | ||
const completed = | ||
isNullish(oldestTxId) || transactions.some(({ id }) => id === oldestTxId); | ||
|
||
if (!completed) { | ||
const lastTx = transactions[transactions.length - 1]; | ||
return getAllTransactionsFromAccountAndIdentity({ | ||
accountId, | ||
identity, | ||
lastTransactionId: lastTx.id, | ||
allTransactions: updatedTransactions, | ||
currentPageIndex: currentPageIndex + 1, | ||
}); | ||
} | ||
|
||
return updatedTransactions; | ||
} catch (error) { | ||
console.error("Error loading ICP account transactions:", error); | ||
return allTransactions; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.