-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(frontend): extract component for IC transactions scrolling
- Loading branch information
1 parent
ff711c3
commit 346572f
Showing
2 changed files
with
64 additions
and
53 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
60 changes: 60 additions & 0 deletions
60
src/frontend/src/icp/components/transactions/IcTransactionsScroll.svelte
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,60 @@ | ||
<script lang="ts"> | ||
import { InfiniteScroll } from '@dfinity/gix-components'; | ||
import { isNullish } from '@dfinity/utils'; | ||
import { icTransactions } from '$icp/derived/ic-transactions.derived'; | ||
import { loadNextTransactions } from '$icp/services/ic-transactions.services'; | ||
import { isNotIcToken, isNotIcTokenCanistersStrict } from '$icp/validation/ic-token.validation'; | ||
import { WALLET_PAGINATION } from '$lib/constants/app.constants'; | ||
import { authIdentity } from '$lib/derived/auth.derived'; | ||
import { nullishSignOut } from '$lib/services/auth.services'; | ||
import { last } from '$lib/utils/array.utils'; | ||
import type { Token } from '$lib/types/token'; | ||
export let token: Token; | ||
let disableInfiniteScroll = false; | ||
const onIntersect = async () => { | ||
if (isNullish($authIdentity)) { | ||
await nullishSignOut(); | ||
return; | ||
} | ||
const lastId = last($icTransactions)?.data.id; | ||
if (isNullish(lastId)) { | ||
// No transactions, we do nothing here and wait for the worker to post the first transactions | ||
return; | ||
} | ||
if (typeof lastId !== 'bigint') { | ||
// Pseudo transactions are displayed at the end of the list. There is not such use case in Oisy. | ||
// Additionally, if it would be the case, that would mean that we display pseudo transactions at the end of the list and therefore we could assume all valid transactions have been fetched | ||
return; | ||
} | ||
if (isNullish(token)) { | ||
// Prevent unlikely events. UI wise if we are about to load the next transactions, it's probably because transactions for a loaded token have been fetched. | ||
return; | ||
} | ||
if (isNotIcToken(token) || isNotIcTokenCanistersStrict(token)) { | ||
// On one hand, we assume that the parent component does not mount this component if no transactions can be fetched; on the other hand, we want to avoid displaying an error toast that could potentially appear multiple times. | ||
// Therefore, we do not particularly display a visual error. In any case, we cannot load transactions without an Index canister. | ||
return; | ||
} | ||
await loadNextTransactions({ | ||
owner: $authIdentity.getPrincipal(), | ||
identity: $authIdentity, | ||
maxResults: WALLET_PAGINATION, | ||
start: lastId, | ||
token, | ||
signalEnd: () => (disableInfiniteScroll = true) | ||
}); | ||
}; | ||
</script> | ||
|
||
<InfiniteScroll on:nnsIntersect={onIntersect} disabled={disableInfiniteScroll}> | ||
<slot /> | ||
</InfiniteScroll> |