-
-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03f046a
commit 0f1719d
Showing
5 changed files
with
174 additions
and
28 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
37 changes: 37 additions & 0 deletions
37
packages/suite/src/views/wallet/transactions/TransactionList/WalletTransactionList.tsx
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,37 @@ | ||
import { selectNetworkTokenDefinitions } from '@suite-common/token-definitions'; | ||
|
||
import { useSelector } from 'src/hooks/suite'; | ||
import { Account, WalletAccountTransaction } from 'src/types/wallet'; | ||
|
||
import { TransactionList } from './TransactionList'; | ||
import { useVisibleTransactionsRetriever } from './useFetchTransactions'; | ||
|
||
interface TransactionListProps { | ||
symbol: WalletAccountTransaction['symbol']; | ||
account: Account; | ||
customTotalItems?: number; | ||
isExportable?: boolean; | ||
} | ||
|
||
export const WalletTransactionList = ({ | ||
account, | ||
symbol, | ||
customTotalItems, | ||
isExportable = true, | ||
}: TransactionListProps) => { | ||
const result = useVisibleTransactionsRetriever({ | ||
account, | ||
}); | ||
|
||
return ( | ||
<TransactionList | ||
allTransactions={result.allTransactions} | ||
transactions={result.visibleTransactions} | ||
symbol={symbol} | ||
account={account} | ||
isLoading={result.isFetching} | ||
customTotalItems={customTotalItems ?? result.visibleTotal} | ||
isExportable={isExportable} | ||
/> | ||
); | ||
}; |
87 changes: 87 additions & 0 deletions
87
...e/src/views/wallet/transactions/TransactionList/__tests__/transaction-fetch-utils.test.ts
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,87 @@ | ||
import { shouldAttemptToLoadNextPageForVisibleTransactions } from '../transaction-fetch-utils'; | ||
|
||
describe('TransactionFetchUtils', () => { | ||
it('should request fetching because the current number of visible transaction is 0 and there are still available', () => { | ||
const result = shouldAttemptToLoadNextPageForVisibleTransactions({ | ||
totalNumberOfTransactions: 100, | ||
currentNumberOfTransactions: 0, | ||
currentNumberOfVisibleTransactions: 0, | ||
perPage: 25, | ||
pagesFetched: 0, | ||
}); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should request fetching because there are still pages a available even though many transactions were filtered', () => { | ||
const result = shouldAttemptToLoadNextPageForVisibleTransactions({ | ||
totalNumberOfTransactions: 100, | ||
currentNumberOfTransactions: 25, | ||
currentNumberOfVisibleTransactions: 0, | ||
perPage: 25, | ||
pagesFetched: 1, | ||
}); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
it("should request fetching because the number of visible pages won't fit even one page", () => { | ||
const result = shouldAttemptToLoadNextPageForVisibleTransactions({ | ||
totalNumberOfTransactions: 100, | ||
currentNumberOfTransactions: 25, | ||
currentNumberOfVisibleTransactions: 10, | ||
perPage: 25, | ||
pagesFetched: 1, | ||
}); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should NOT request fetching because the number of visible pages will fit even one page', () => { | ||
const result = shouldAttemptToLoadNextPageForVisibleTransactions({ | ||
totalNumberOfTransactions: 100, | ||
currentNumberOfTransactions: 25, | ||
currentNumberOfVisibleTransactions: 25, | ||
perPage: 25, | ||
pagesFetched: 1, | ||
}); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should request fetching because there is too little number of page for 2 pages', () => { | ||
const result = shouldAttemptToLoadNextPageForVisibleTransactions({ | ||
totalNumberOfTransactions: 100, | ||
currentNumberOfTransactions: 50, | ||
currentNumberOfVisibleTransactions: 40, | ||
perPage: 25, | ||
pagesFetched: 2, | ||
}); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should request fetching because there is too little number of page for 3 pages', () => { | ||
const result = shouldAttemptToLoadNextPageForVisibleTransactions({ | ||
totalNumberOfTransactions: 100, | ||
currentNumberOfTransactions: 75, | ||
currentNumberOfVisibleTransactions: 50, | ||
perPage: 25, | ||
pagesFetched: 3, | ||
}); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should NOT request fetching any more pages because there are not any left', () => { | ||
const result = shouldAttemptToLoadNextPageForVisibleTransactions({ | ||
totalNumberOfTransactions: 100, | ||
currentNumberOfTransactions: 100, | ||
currentNumberOfVisibleTransactions: 2, | ||
perPage: 25, | ||
pagesFetched: 1, | ||
}); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
packages/suite/src/views/wallet/transactions/TransactionList/transaction-fetch-utils.ts
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,36 @@ | ||
export function shouldAttemptToLoadNextPageForVisibleTransactions({ | ||
totalNumberOfTransactions, | ||
currentNumberOfTransactions, | ||
currentNumberOfVisibleTransactions, | ||
perPage, | ||
pagesFetched, | ||
}: { | ||
totalNumberOfTransactions: number; | ||
perPage: number; | ||
currentNumberOfTransactions: number; | ||
currentNumberOfVisibleTransactions: number; | ||
pagesFetched: number; | ||
}): boolean { | ||
if (totalNumberOfTransactions === 0) return false; | ||
|
||
if ( | ||
currentNumberOfVisibleTransactions === currentNumberOfTransactions && | ||
currentNumberOfVisibleTransactions !== 0 | ||
) | ||
return false; | ||
|
||
if (totalNumberOfTransactions <= currentNumberOfTransactions) return false; | ||
|
||
const itemsIfAllDisplayed = pagesFetched * perPage; | ||
|
||
if (itemsIfAllDisplayed > currentNumberOfVisibleTransactions) return true; | ||
|
||
const fetchedPagesByTransactions = Math.ceil(currentNumberOfTransactions / perPage); | ||
const pagesByVisibleTransactions = Math.floor(currentNumberOfVisibleTransactions / perPage); | ||
|
||
if (pagesByVisibleTransactions === 0 && totalNumberOfTransactions > 0) return true; | ||
|
||
if (fetchedPagesByTransactions <= pagesByVisibleTransactions) return false; | ||
|
||
return true; | ||
} |
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