Skip to content

Commit

Permalink
Merge pull request #1125 from urbit/st/reset-store-logout
Browse files Browse the repository at this point in the history
Clear state on logout
  • Loading branch information
pkova authored Oct 9, 2023
2 parents 703ff86 + dbd3684 commit ce4e43f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/components/L2/Dropdowns/AccountsDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useCallback, useMemo, useState } from 'react';
import { Icon, Row, Box } from '@tlon/indigo-react';
import { Just } from 'folktale/maybe';

import LayerIndicator from 'components/L2/LayerIndicator';
import CopiableAddressWrap from 'components/copiable/CopiableAddressWrap';
import { TooltipPosition } from 'components/WithTooltip';
Expand All @@ -26,7 +25,7 @@ const AccountsDropdown = ({ showMigrate = false }: AccountsDropdownProps) => {
const walletInfo: any = useWallet();
const { push, popTo, names, reset }: any = useHistory();
const { setPointCursor }: any = usePointCursor();
const { point, pointList } = useRollerStore();
const { point, pointList, resetStore } = useRollerStore();

const canBitcoin = Just.hasInstance(walletInfo.urbitWallet);

Expand Down Expand Up @@ -65,7 +64,8 @@ const AccountsDropdown = ({ showMigrate = false }: AccountsDropdownProps) => {

const onLogout = () => {
clearInvitesStorage();
reset();
reset(); // router
resetStore();
};

const hasL1Points = Boolean(pointList.find(({ layer }) => layer === 1));
Expand Down
15 changes: 13 additions & 2 deletions src/store/rollerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const EMPTY_POINT = new Point({
address: '',
});

export interface RollerStore {
export interface RollerState {
loading: boolean;
nextQuotaTime: number;
pendingTransactions: PendingTransaction[];
Expand All @@ -31,6 +31,9 @@ export interface RollerStore {
modalText?: string;
recentlyCompleted: number;
ethBalance: BN;
}

export interface RollerActions {
setLoading: (loading: boolean) => void;
setModalText: (modalText: string) => void;
setNextQuotaTime: (nextQuotaTime: number) => void;
Expand All @@ -41,9 +44,10 @@ export interface RollerStore {
storePendingL1Txn: (txn: PendingL1Txn) => void;
deletePendingL1Txn: (txn: PendingL1Txn) => void;
setEthBalance: (ethBalance: BN) => void;
resetStore: () => void;
}

export const useRollerStore = create<RollerStore>(set => ({
const initialRollerState: RollerState = {
loading: false,
nextQuotaTime: new Date().getTime() + 24 * HOUR,
pendingTransactions: [],
Expand All @@ -53,6 +57,10 @@ export const useRollerStore = create<RollerStore>(set => ({
pendingL1ByPoint: {},
recentlyCompleted: 0,
ethBalance: toBN(0),
};

export const useRollerStore = create<RollerState & RollerActions>(set => ({
...initialRollerState,
setLoading: (loading: boolean) => set(() => ({ loading })),
setNextQuotaTime: (nextQuotaTime: number) => set(() => ({ nextQuotaTime })),
setPendingTransactions: (pendingTransactions: PendingTransaction[]) =>
Expand Down Expand Up @@ -92,4 +100,7 @@ export const useRollerStore = create<RollerStore>(set => ({
return { pendingL1ByPoint: newPending };
}),
setEthBalance: (ethBalance: BN) => set(() => ({ ethBalance })),
resetStore: () => {
set(initialRollerState);
},
}));

0 comments on commit ce4e43f

Please sign in to comment.