Skip to content

Commit

Permalink
refactor: Improve handling of transfers in Transactions component
Browse files Browse the repository at this point in the history
  • Loading branch information
Da-Colon committed Aug 12, 2024
1 parent 2e1a548 commit e7ee544
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 19 deletions.
10 changes: 6 additions & 4 deletions src/components/pages/DAOTreasury/components/Transactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ function EmptyTransactions() {

export function Transactions({ shownTransactions }: { shownTransactions: number }) {
const {
treasury: { transfers, transfersLoaded, transfersLoading },
treasury: { transfers, transfersLoaded },
} = useFractal();

if (!transfers || (transfers.length === 0 && transfersLoaded)) return <EmptyTransactions />;

if (!transfers) {
return null;
}
if (transfers.length === 0 && transfersLoaded) return <EmptyTransactions />;
return (
<Box
overflowX="auto"
Expand All @@ -127,7 +129,7 @@ export function Transactions({ shownTransactions }: { shownTransactions: number
displayData={transfer}
/>
))}
{(transfersLoading || !transfersLoaded) && <Box>{/* @todo add Wave Loader */}</Box>}
{(transfers === null || !transfersLoaded) && <Box>{/* @todo add Wave Loader */}</Box>}
</Box>
);
}
Expand Down
3 changes: 0 additions & 3 deletions src/hooks/DAO/loaders/useDecentTreasury.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const useDecentTreasury = () => {
if (!daoAddress || !safeAPI) {
return;
}
action.dispatch({ type: TreasuryAction.SET_TRANSFERS_LOADING, payload: true });
const [
transfers,
{ data: tokenBalances, error: tokenBalancesError },
Expand Down Expand Up @@ -147,8 +146,6 @@ export const useDecentTreasury = () => {
action.dispatch({ type: TreasuryAction.SET_TRANSFERS_LOADED, payload: true });
}
});

action.dispatch({ type: TreasuryAction.SET_TRANSFERS_LOADING, payload: false });
}, [
daoAddress,
safeAPI,
Expand Down
4 changes: 0 additions & 4 deletions src/providers/App/treasury/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ export type TreasuryActions =
type: TreasuryAction.ADD_TRANSFER;
payload: TransferDisplayData;
}
| {
type: TreasuryAction.SET_TRANSFERS_LOADING;
payload: boolean;
}
| {
type: TreasuryAction.SET_TRANSFERS_LOADED;
payload: boolean;
Expand Down
7 changes: 1 addition & 6 deletions src/providers/App/treasury/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { TreasuryActions, TreasuryAction } from './action';
export const initialTreasuryState: DecentTreasury = {
assetsFungible: [],
assetsNonFungible: [],
transfers: undefined,
transfers: null,
totalUsdValue: 0,
transfersLoading: true,
transfersLoaded: false,
};

Expand All @@ -17,10 +16,6 @@ export const treasuryReducer = (state: DecentTreasury, action: TreasuryActions):
case TreasuryAction.ADD_TRANSFER:
const transfers = state.transfers ?? [];
return { ...state, transfers: [...transfers, action.payload] };
case TreasuryAction.SET_TRANSFERS_LOADING:
return { ...state, transfersLoading: action.payload };
case TreasuryAction.SET_TRANSFERS_LOADED:
return { ...state, transfersLoaded: true };
case TreasuryAction.RESET:
return initialTreasuryState;
default:
Expand Down
3 changes: 1 addition & 2 deletions src/types/fractal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ export interface DecentTreasury {
totalUsdValue: number;
assetsFungible: TokenBalance[];
assetsNonFungible: NFTBalance[];
transfers?: TransferDisplayData[];
transfersLoading?: boolean;
transfers?: TransferDisplayData[] | null;
transfersLoaded?: boolean;
}

Expand Down

0 comments on commit e7ee544

Please sign in to comment.