Skip to content

Commit

Permalink
wip: add T&Cs version (#1409)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjeatt authored Jul 4, 2023
1 parent 4d5576f commit fcdb5af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/utils/hooks/use-local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { useLocalStorage as useLibLocalStorage } from 'react-use';

enum LocalStorageKey {
TC_SIGNATURES = 'TC_SIGNATURES',
TC_VERSION = 'TC_VERSION',
WALLET_WELCOME_BANNER = 'WALLET_WELCOME_BANNER'
}

type LocalStorageValueTypes = {
[LocalStorageKey.TC_SIGNATURES]: Record<string, boolean>;
[LocalStorageKey.TC_VERSION]: string;
[LocalStorageKey.WALLET_WELCOME_BANNER]: boolean;
};

Expand Down
11 changes: 11 additions & 0 deletions src/utils/hooks/use-sign-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface GetSignatureData {
exists: boolean;
}

const TC_VERSION = '1.0';

const postSignature = async (account: KeyringPair) => {
const signerResult = await signMessage(account, TERMS_AND_CONDITIONS_LINK);

Expand Down Expand Up @@ -57,6 +59,8 @@ const useSignMessage = (): UseSignMessageResult => {

const dispatch = useDispatch();
const [signatures, setSignatures] = useLocalStorage(LocalStorageKey.TC_SIGNATURES);
const [tcVersion, setTcVersion] = useLocalStorage(LocalStorageKey.TC_VERSION);

const { selectedAccount } = useSubstrateSecureState();

const setSignature = useCallback(
Expand Down Expand Up @@ -109,6 +113,7 @@ const useSignMessage = (): UseSignMessageResult => {
},
onSuccess: (_, variables) => {
setSignature(variables.address, true);
setTcVersion(TC_VERSION);
dispatch(showSignTermsModalAction(false));
refetchSignatureData();
notifications.show(variables.address, {
Expand All @@ -118,6 +123,12 @@ const useSignMessage = (): UseSignMessageResult => {
}
});

useEffect(() => {
if (tcVersion === TC_VERSION) return;

setSignatures({});
}, [setSignatures, tcVersion]);

// Reset mutation on account change
useEffect(() => {
if (signMessageMutation.isLoading && selectedAccount?.address) {
Expand Down

2 comments on commit fcdb5af

@vercel
Copy link

@vercel vercel bot commented on fcdb5af Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on fcdb5af Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.