Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 4 additions & 11 deletions packages/libs/ui/token-gate/src/lib/TokenVerify.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';

Check warning on line 1 in packages/libs/ui/token-gate/src/lib/TokenVerify.tsx

View workflow job for this annotation

GitHub Actions / main (18.x)

'useEffect' is defined but never used

Check warning on line 1 in packages/libs/ui/token-gate/src/lib/TokenVerify.tsx

View workflow job for this annotation

GitHub Actions / main (16.x)

'useEffect' is defined but never used

Check warning on line 1 in packages/libs/ui/token-gate/src/lib/TokenVerify.tsx

View workflow job for this annotation

GitHub Actions / main (20.x)

'useEffect' is defined but never used
import VerificationModal from './VerificationModal';
import VerifyButton from './VerifyButton';
import { createGlobalState } from 'react-hooks-global-state';
Expand All @@ -10,12 +10,10 @@
appElement: string;
quicknodeUrl: string;
nftContractAddress: string;
verificationMessage?: string;
}

// Using this global state to persist the verification state between page navigation
// TODO: Can we do this with a localstorage or a cookie in a secure way?
// that can't be faked by non-nft holders with an expiration?
// TODO: Can we use redux here?
Copy link
Contributor

Choose a reason for hiding this comment

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

@kayvee-x are these TODOs addressed by these changes?

const initialState = { fullyVerified: false, isModalOpen: false };
const { useGlobalState } = createGlobalState<{
fullyVerified: boolean;
Expand All @@ -27,6 +25,7 @@
appElement,
nftContractAddress,
quicknodeUrl,
verificationMessage = 'This message is used to verify your wallet ownership.\n\nSigning this message will not make any transactions.',
}: TokenGateProps) {
const browserProvider = new ethers.BrowserProvider((window as any).ethereum);
const qnProvider = new JsonRpcProvider(quicknodeUrl);
Expand Down Expand Up @@ -82,12 +81,7 @@

async function validateWallet() {
const signer = await browserProvider.getSigner();
// TODO: make message customizable
const message =
'This message is used to verify your wallet ownership.\n\nSigning this message will not make any transactions.';
await signer.signMessage(message);
// TODO: Store the hashed message, and re-verify hash instead of having to ask wallet to sign each time
// https://github.com/ethers-io/ethers.js/issues/447
Copy link
Contributor

Choose a reason for hiding this comment

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

@kayvee-x does this address this TODO?

await signer.signMessage(verificationMessage);
setOwnershipStatus(OWNERSHIP_STATUS.SIGNED);
}

Expand All @@ -103,8 +97,7 @@
}
} catch (e) {
console.error(e);
// TODO: make an error handler status
setOwnershipStatus(OWNERSHIP_STATUS.DENIED);
setOwnershipStatus(OWNERSHIP_STATUS.ERROR);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/libs/ui/token-gate/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum OWNERSHIP_STATUS {
'VERIFIED',
'SIGNED',
'DENIED',
'ERROR',
}

export enum WALLET_PROVIDERS {
Expand Down
Loading