Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tx history pagination #1558

Merged
merged 28 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2f376f6
feat: add pagination parameter
helciofranco Oct 7, 2024
29299db
feat: save tx list page info to the machine
helciofranco Oct 7, 2024
bffa34c
feat: add fetch more event
helciofranco Oct 7, 2024
5e3b318
chore: remove unused stuff
helciofranco Oct 7, 2024
ea8a216
feat: fetch first 20
helciofranco Oct 7, 2024
3ff1d63
feat: set wallet address when needed
helciofranco Oct 7, 2024
8d6aeca
feat: add reverse pagination
helciofranco Oct 7, 2024
4c3220f
feat: add more args
helciofranco Oct 7, 2024
bda81d5
feat: add reverse pagination
helciofranco Oct 7, 2024
9908250
fix: remove unnecessary reverse
helciofranco Oct 7, 2024
75df107
chore: rename to next page again
helciofranco Oct 7, 2024
22ac31c
chore: remove sort
helciofranco Oct 7, 2024
6f6a5bc
feat: add transactions cursors table
helciofranco Oct 7, 2024
0c11b6a
Merge branch 'master' of github.com:FuelLabs/fuels-wallet into hf/fea…
helciofranco Oct 7, 2024
4636db2
chore: get tx cursors based on provider url and address
helciofranco Oct 7, 2024
742f4ed
feat: add initial end cursor to get all the latest cursos
helciofranco Oct 7, 2024
a34da4a
feat: add tx history machine
helciofranco Oct 7, 2024
c801b7f
docs: add changeset
helciofranco Oct 7, 2024
83b3387
feat: add fetch new page states
helciofranco Oct 7, 2024
8245515
fix: flick tx list screen
helciofranco Oct 7, 2024
0dfc558
feat: add automatic fetch next page
helciofranco Oct 7, 2024
338fb73
chore: increase tx page
helciofranco Oct 7, 2024
7779339
chore: merge migration
helciofranco Oct 8, 2024
1045d96
Merge branch 'master' into hf/feat/tx-history-pagination
helciofranco Oct 8, 2024
6741c85
chore
LuizAsFight Oct 8, 2024
a137ea7
Merge branch 'master' into hf/feat/tx-history-pagination
LuizAsFight Oct 8, 2024
4843dfb
chore
LuizAsFight Oct 8, 2024
0cdc6e1
Merge branch 'hf/feat/tx-history-pagination' of github.com:FuelLabs/f…
LuizAsFight Oct 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tough-oranges-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels-wallet": minor
---

Add pagination to the Transaction History screen.
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fuels-wallet",
"private": true,
"version": "0.34.1",
"database": "21",
"database": "23",
"scripts": {
"build:all": "run-s build:web build:crx build:storybook",
"build:web": "./scripts/build.sh --app=vite",
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/systems/Core/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
import type { DbEvents, PromiseExtended, Table } from 'dexie';
import Dexie from 'dexie';
import 'dexie-observable';
import type { Transaction } from '~/systems/Transaction/types';
import type { TransactionCursor } from '~/systems/Transaction';
import { applyDbVersioning } from './databaseVersioning';

type FailureEvents = Extract<keyof DbEvents, 'close' | 'blocked'>;
Expand All @@ -22,7 +22,7 @@ export class FuelDB extends Dexie {
accounts!: Table<Account, string>;
networks!: Table<NetworkData, string>;
connections!: Table<Connection, string>;
transactions!: Table<Transaction, string>;
transactionsCursors!: Table<TransactionCursor, string>;
assets!: Table<AssetData, string>;
abis!: Table<AbiTable, string>;
errors!: Table<StoredFuelWalletError, string>;
Expand Down Expand Up @@ -89,7 +89,7 @@ export class FuelDB extends Dexie {
this.accounts.clear(),
this.networks.clear(),
this.connections.clear(),
this.transactions.clear(),
this.transactionsCursors.clear(),
this.assets.clear(),
this.abis.clear(),
this.errors.clear(),
Expand Down
16 changes: 15 additions & 1 deletion packages/app/src/systems/Core/utils/databaseVersioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export const applyDbVersioning = (db: Dexie) => {
connections: 'origin',
transactions: '&id',
assets: '&name, &symbol',
assetsTemp: null,
abis: '&contractId',
errors: '&id',
})
Expand All @@ -124,4 +123,19 @@ export const applyDbVersioning = (db: Dexie) => {
});
}
});

// DB VERSION 23
// 1. Drop transactions table since we don't use that anymore
// 2. Add cursors table for handling tx pagination
db.version(23).stores({
vaults: 'key',
accounts: '&address, &name',
networks: '&id, &url, &name, chainId',
connections: 'origin',
transactions: null,
transactionsCursors: '++id, address, providerUrl, endCursor',
assets: '&name, &symbol',
abis: '&contractId',
errors: '&id',
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useInterpret, useSelector } from '@xstate/react';
import type { Address } from 'fuels';
import { useEffect } from 'react';

import type { TransactionHistoryMachineState } from '../machines';
import { transactionHistoryMachine } from '../machines';
import type { TxInputs } from '../services';

const selectors = {
isFetching: (state: TransactionHistoryMachineState) => {
return state.hasTag('loading');
},
isFetchingNextPage: (state: TransactionHistoryMachineState) => {
return state.matches('fetchingNextPage');
},
transactionHistory: (state: TransactionHistoryMachineState) => {
return state.context.transactionHistory;
},
hasNextPage: (state: TransactionHistoryMachineState) => {
const hasCurrentCursor = Boolean(state.context.currentCursor);
const hasLoadedTxs = Boolean(state.context.transactionHistory?.length);
return hasCurrentCursor && hasLoadedTxs;
},
};

type UseTransactionHistoryProps = {
address?: string | Address;
};

export function useTransactionHistory({ address }: UseTransactionHistoryProps) {
const service = useInterpret(() => transactionHistoryMachine);
const { send } = service;
const isFetching = useSelector(service, selectors.isFetching);
const isFetchingNextPage = useSelector(service, selectors.isFetchingNextPage);
const transactionHistory = useSelector(service, selectors.transactionHistory);
const hasNextPage = useSelector(service, selectors.hasNextPage);

function getTransactionHistory(input: TxInputs['getTransactionHistory']) {
send('GET_TRANSACTION_HISTORY', { input });
}

function fetchNextPage() {
send('FETCH_NEXT_PAGE');
}

useEffect(() => {
if (address) {
getTransactionHistory({ address: address.toString() });
}
}, [address]);

return {
fetchNextPage,
isFetching,
isFetchingNextPage,
transactionHistory,
hasNextPage,
};
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export function useTxMetadata({
// Avoid screen to break with empty operations
const mainOperation = operations[0] || {};
const label = getLabel(mainOperation, account?.address as Bech32Address);
const timeFormatted = time ? formatDate(time) : undefined;
const timeFormattedRaw = time ? formatDate(time) : undefined;
const timeFormatted = timeFormattedRaw?.replace(
'a few seconds ago',
'seconds ago'
);

const toOrFromText = useMemo(() => {
const opDirection = getOperationDirection(mainOperation, ownerAddress);
Expand Down
Loading
Loading