Skip to content

Commit 3f59adc

Browse files
committed
Merge branch 'develop' into preview
2 parents 8b23a81 + 6f567a3 commit 3f59adc

File tree

6 files changed

+196
-0
lines changed

6 files changed

+196
-0
lines changed

app/globals.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
@tailwind base;
22
@tailwind components;
33
@tailwind utilities;
4+
5+
.text-tono-gradient {
6+
@apply text-transparent uppercase bg-clip-text bg-gradient-to-r from-[#F0B5B3] via-[#E47673] to-[#F0B5B3];
7+
}

app/verify/page.tsx

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
"use client";
2+
3+
import { Suspense, useCallback, useState } from "react";
4+
import { Header } from "@/components/header/header";
5+
import {
6+
Button,
7+
Modal,
8+
ModalContent,
9+
ModalOverlay,
10+
ModalPortal,
11+
Typography,
12+
} from "@mochi-ui/core";
13+
import { useDisclosure } from "@dwarvesf/react-hooks";
14+
import { LoginWidget } from "@mochi-web3/login-widget";
15+
import { useSearchParams } from "next/navigation";
16+
import { WretchError } from "wretch";
17+
import { API } from "@/constants/api";
18+
19+
const Verify = () => {
20+
const { isOpen, onOpenChange } = useDisclosure();
21+
const searchParams = useSearchParams();
22+
const [loading, setLoading] = useState(false);
23+
const [verified, setVerified] = useState(false);
24+
const [error, _setError] = useState("");
25+
const setError = useCallback(
26+
(e: WretchError) => {
27+
_setError(e.json?.msg ?? "Something went wrong");
28+
},
29+
[_setError]
30+
);
31+
32+
const code = searchParams.get("code");
33+
const guild_id = searchParams.get("guild_id");
34+
35+
if (error) {
36+
return (
37+
<div className="py-8 px-8 mx-auto md:px-16 md:max-w-2xl min-h-[calc(100vh-56px)] flex flex-col items-center justify-center">
38+
<div className="mb-2 font-medium text-center md:text-xl">
39+
Something went wrong with error
40+
</div>
41+
<div className="py-2 px-4 w-full font-mono rounded bg-stone-200">
42+
&ldquo;{error}&rdquo;
43+
</div>
44+
</div>
45+
);
46+
}
47+
48+
if (verified) {
49+
return (
50+
<div className="py-8 px-8 mx-auto md:px-16 md:max-w-2xl min-h-[calc(100vh-56px)] flex flex-col items-center justify-center">
51+
<div className="text-2xl font-black text-center md:text-3xl">
52+
<span className="uppercase text-tono-gradient">
53+
Your wallet is verified! You can close this window
54+
</span>{" "}
55+
56+
</div>
57+
</div>
58+
);
59+
}
60+
61+
return (
62+
<div className="w-full min-h-[calc(100vh-56px)] flex flex-col items-center justify-center text-center px-4 space-y-6">
63+
<Typography
64+
level="h4"
65+
className="mb-4 text-center uppercase !font-black text-tono-gradient"
66+
>
67+
Verify your wallet
68+
</Typography>
69+
<Typography level="p3" className="mb-3 text-center max-w-md">
70+
Connect your wallet to verify and get full access to Tono with more
71+
exclusive privileges.
72+
</Typography>
73+
<div>
74+
<Modal open={isOpen} onOpenChange={onOpenChange}>
75+
<ModalPortal>
76+
<ModalOverlay />
77+
<ModalContent
78+
className="p-3 w-full sm:w-auto"
79+
style={{
80+
maxWidth: "calc(100% - 32px)",
81+
}}
82+
>
83+
<LoginWidget
84+
raw
85+
onchain
86+
onWalletConnectSuccess={async ({
87+
address,
88+
signature,
89+
platform,
90+
}) => {
91+
if (!code || loading) return;
92+
setLoading(true);
93+
const payload = {
94+
wallet_address: address,
95+
code,
96+
signature,
97+
message:
98+
"Please sign this message to prove wallet ownership",
99+
};
100+
101+
await API.MOCHI_PROFILE.post(
102+
payload,
103+
`/profiles/me/accounts/connect-${platform.replace(
104+
"-chain",
105+
""
106+
)}`
107+
)
108+
.badRequest(setError)
109+
.json(async (r) => {
110+
const user_discord_id = r.associated_accounts.find(
111+
(aa: any) => aa.platform === "discord"
112+
)?.platform_identifier;
113+
if (!guild_id) {
114+
setVerified(true);
115+
} else if (user_discord_id) {
116+
await API.MOCHI.post(
117+
{
118+
user_discord_id,
119+
guild_id,
120+
},
121+
`/verify/assign-role`
122+
)
123+
.badRequest(setError)
124+
.res(() => {
125+
setVerified(true);
126+
})
127+
.catch(setError)
128+
.finally(() => {
129+
setLoading(false);
130+
onOpenChange(false);
131+
});
132+
}
133+
});
134+
}}
135+
/>
136+
</ModalContent>
137+
</ModalPortal>
138+
</Modal>
139+
<Button color="primary" onClick={() => onOpenChange(true)}>
140+
Verify
141+
</Button>
142+
</div>
143+
</div>
144+
);
145+
};
146+
147+
export default function Page() {
148+
return (
149+
<main>
150+
<Header />
151+
<Suspense>
152+
<Verify />
153+
</Suspense>
154+
</main>
155+
);
156+
}

constants/api.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import wretch from "wretch";
2+
import QueryStringAddon from "wretch/addons/queryString";
3+
import AbortAddon from "wretch/addons/abort";
4+
5+
import { MOCHI_PAY_API, MOCHI_PROFILE_API, MOCHI_API } from "../envs";
6+
7+
const MOCHI_PROFILE = wretch(MOCHI_PROFILE_API)
8+
.addon(QueryStringAddon)
9+
.addon(AbortAddon())
10+
.errorType("json");
11+
12+
const MOCHI_PAY = wretch(MOCHI_PAY_API)
13+
.addon(QueryStringAddon)
14+
.addon(AbortAddon())
15+
.errorType("json");
16+
17+
const MOCHI = wretch(MOCHI_API)
18+
.addon(QueryStringAddon)
19+
.addon(AbortAddon())
20+
.errorType("json");
21+
22+
export const API = {
23+
MOCHI_PROFILE,
24+
MOCHI_PAY,
25+
MOCHI,
26+
};

envs.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ export const AUTH_TELEGRAM_ID = process.env.NEXT_PUBLIC_AUTH_TELEGRAM_ID || "";
22
export const MOCHI_PROFILE_API = `${
33
process.env.NEXT_PUBLIC_MOCHI_PROFILE_API_HOST || "mochi-profile-api"
44
}/api/v1`;
5+
export const MOCHI_PAY_API = `${
6+
process.env.NEXT_PUBLIC_MOCHI_PAY_API_HOST || "mochi-pay-api"
7+
}/api/v1`;
8+
export const MOCHI_API = `${
9+
process.env.NEXT_PUBLIC_MOCHI_API_HOST || "mochi-api"
10+
}/api/v1`;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"react-dom": "^18",
2929
"swr": "^2.2.5",
3030
"tailwindcss-animate": "^1.0.7",
31+
"wretch": "^2.8.1",
3132
"zustand": "^4.5.2"
3233
},
3334
"devDependencies": {

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)