Skip to content

Commit

Permalink
bug/T&C: fix new user signing, maintain signing hist, main domain too…
Browse files Browse the repository at this point in the history
… big
  • Loading branch information
akiraonstarknet committed Oct 1, 2024
1 parent 15aff9e commit 14d931f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
14 changes: 14 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ model User {
createdAt DateTime @default(now())
og_nft_users og_nft_users?
updatedAt DateTime @updatedAt
Signatures Signatures[]
}

model Signatures {
id Int @id @default(autoincrement())
signature String
tncDocVersion String
createdAt DateTime @default(now())
userId Int
User User @relation(fields: [userId], references: [id])
@@unique([userId, tncDocVersion], name: "unique_signature")
}

model Referral {
Expand Down
3 changes: 3 additions & 0 deletions src/app/api/tnc/getUser/[address]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export async function GET(_req: Request, context: any) {
where: {
address: parsedAddress,
},
include: {
Signatures: true,
},
});

if (!user) {
Expand Down
10 changes: 9 additions & 1 deletion src/app/api/tnc/signUser/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function POST(req: Request) {
if (!isValid) {
return NextResponse.json({
success: false,
message: 'Invalid signature',
message: 'Invalid signature. Ensure account is deployed.',
user: null,
});
}
Expand All @@ -81,6 +81,14 @@ export async function POST(req: Request) {
message: signature,
isTncSigned: true,
tncDocVersion: LATEST_TNC_DOC_VERSION,
Signatures: {
create: [
{
signature,
tncDocVersion: LATEST_TNC_DOC_VERSION,
},
],
},
},
});

Expand Down
10 changes: 9 additions & 1 deletion src/components/TncModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ import { useSearchParams } from 'next/navigation';
import { generateReferralCode } from '@/utils';
import { ExternalLinkIcon } from '@chakra-ui/icons';
import mixpanel from 'mixpanel-browser';
import toast from 'react-hot-toast';

interface TncModalProps {}

export const UserTnCAtom = atomWithQuery((get) => {
return {
queryKey: ['tnc', get(addressAtom)],
// we use referral code atom as key to ensure user exisits in db by then
queryKey: ['tnc', get(addressAtom), get(referralCodeAtom)],
queryFn: async (): Promise<null | UserTncInfo> => {
const address: string | undefined = get(addressAtom);
console.log(`address tnc`, address);
if (!address) return null;
const res = await axios.get(`/api/tnc/getUser/${address}`);
return res.data;
Expand Down Expand Up @@ -109,6 +112,8 @@ const TncModal: React.FC<TncModalProps> = (props) => {

if (res2.data?.success) {
onClose();
} else {
toast.error(res2.data?.message || 'Error verifying T&C');
}
}
} catch (error) {
Expand Down Expand Up @@ -201,6 +206,9 @@ const TncModal: React.FC<TncModalProps> = (props) => {
Disconnect
</Button>
</Center>
<Text textAlign={'center'} color={'light_grey'} fontSize={'12px'}>
Note: Only deployed accounts can sign
</Text>
</ModalBody>
</ModalContent>
</Modal>
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const SIGNING_DATA = {
},
message: {
message: 'Read and Agree T&C',
document: `${getEndpoint()}/${LATEST_TNC_DOC_VERSION}`,
document: `${getEndpoint().replace('https://', '').replace('http://', '')}/${LATEST_TNC_DOC_VERSION}`,
},
};

Expand Down

0 comments on commit 14d931f

Please sign in to comment.