on master help sign in
Merge pull request #1125 from urbit/st/reset-store-logout
ce4e43fPyry Kovanen
src/components/L2/Dropdowns/AccountsDropdown.tsx+3−3
@@ -1,7 +1,6 @@
1import { useCallback, useMemo, useState } from 'react';
1import { useCallback, useMemo, useState } from 'react';
2import { Icon, Row, Box } from '@tlon/indigo-react';
2import { Icon, Row, Box } from '@tlon/indigo-react';
3import { Just } from 'folktale/maybe';
3import { Just } from 'folktale/maybe';
4−
5import LayerIndicator from 'components/L2/LayerIndicator';
4import LayerIndicator from 'components/L2/LayerIndicator';
6import CopiableAddressWrap from 'components/copiable/CopiableAddressWrap';
5import CopiableAddressWrap from 'components/copiable/CopiableAddressWrap';
7import { TooltipPosition } from 'components/WithTooltip';
6import { TooltipPosition } from 'components/WithTooltip';
@@ -26,7 +25,7 @@ const AccountsDropdown = ({ showMigrate = false }: AccountsDropdownProps) => {
26 const walletInfo: any = useWallet();
25 const walletInfo: any = useWallet();
27 const { push, popTo, names, reset }: any = useHistory();
26 const { push, popTo, names, reset }: any = useHistory();
28 const { setPointCursor }: any = usePointCursor();
27 const { setPointCursor }: any = usePointCursor();
29− const { point, pointList } = useRollerStore();
28+ const { point, pointList, resetStore } = useRollerStore();
30
29
31 const canBitcoin = Just.hasInstance(walletInfo.urbitWallet);
30 const canBitcoin = Just.hasInstance(walletInfo.urbitWallet);
32
31
@@ -65,7 +64,8 @@ const AccountsDropdown = ({ showMigrate = false }: AccountsDropdownProps) => {
65
64
66 const onLogout = () => {
65 const onLogout = () => {
67 clearInvitesStorage();
66 clearInvitesStorage();
68− reset();
67+ reset(); // router
68+ resetStore();
69 };
69 };
70
70
71 const hasL1Points = Boolean(pointList.find(({ layer }) => layer === 1));
71 const hasL1Points = Boolean(pointList.find(({ layer }) => layer === 1));
src/store/rollerStore.ts+13−2
@@ -20,7 +20,7 @@ export const EMPTY_POINT = new Point({
20 address: '',
20 address: '',
21});
21});
22
22
23−export interface RollerStore {
23+export interface RollerState {
24 loading: boolean;
24 loading: boolean;
25 nextQuotaTime: number;
25 nextQuotaTime: number;
26 pendingTransactions: PendingTransaction[];
26 pendingTransactions: PendingTransaction[];
@@ -31,6 +31,9 @@ export interface RollerStore {
31 modalText?: string;
31 modalText?: string;
32 recentlyCompleted: number;
32 recentlyCompleted: number;
33 ethBalance: BN;
33 ethBalance: BN;
34+}
35+
36+export interface RollerActions {
34 setLoading: (loading: boolean) => void;
37 setLoading: (loading: boolean) => void;
35 setModalText: (modalText: string) => void;
38 setModalText: (modalText: string) => void;
36 setNextQuotaTime: (nextQuotaTime: number) => void;
39 setNextQuotaTime: (nextQuotaTime: number) => void;
@@ -41,9 +44,10 @@ export interface RollerStore {
41 storePendingL1Txn: (txn: PendingL1Txn) => void;
44 storePendingL1Txn: (txn: PendingL1Txn) => void;
42 deletePendingL1Txn: (txn: PendingL1Txn) => void;
45 deletePendingL1Txn: (txn: PendingL1Txn) => void;
43 setEthBalance: (ethBalance: BN) => void;
46 setEthBalance: (ethBalance: BN) => void;
47+ resetStore: () => void;
44}
48}
45
49
46−export const useRollerStore = create<RollerStore>(set => ({
50+const initialRollerState: RollerState = {
47 loading: false,
51 loading: false,
48 nextQuotaTime: new Date().getTime() + 24 * HOUR,
52 nextQuotaTime: new Date().getTime() + 24 * HOUR,
49 pendingTransactions: [],
53 pendingTransactions: [],
@@ -53,6 +57,10 @@ export const useRollerStore = create<RollerStore>(set => ({
53 pendingL1ByPoint: {},
57 pendingL1ByPoint: {},
54 recentlyCompleted: 0,
58 recentlyCompleted: 0,
55 ethBalance: toBN(0),
59 ethBalance: toBN(0),
60+};
61+
62+export const useRollerStore = create<RollerState & RollerActions>(set => ({
63+ ...initialRollerState,
56 setLoading: (loading: boolean) => set(() => ({ loading })),
64 setLoading: (loading: boolean) => set(() => ({ loading })),
57 setNextQuotaTime: (nextQuotaTime: number) => set(() => ({ nextQuotaTime })),
65 setNextQuotaTime: (nextQuotaTime: number) => set(() => ({ nextQuotaTime })),
58 setPendingTransactions: (pendingTransactions: PendingTransaction[]) =>
66 setPendingTransactions: (pendingTransactions: PendingTransaction[]) =>
@@ -92,4 +100,7 @@ export const useRollerStore = create<RollerStore>(set => ({
92 return { pendingL1ByPoint: newPending };
100 return { pendingL1ByPoint: newPending };
93 }),
101 }),
94 setEthBalance: (ethBalance: BN) => set(() => ({ ethBalance })),
102 setEthBalance: (ethBalance: BN) => set(() => ({ ethBalance })),
103+ resetStore: () => {
104+ set(initialRollerState);
105+ },
95}));
106}));