From e75a447a27952889b016e08d17a4c6a5270a423b Mon Sep 17 00:00:00 2001 From: sven Tan Date: Tue, 10 Dec 2024 11:48:43 +0800 Subject: [PATCH] add loop check twitter obj --- .../src/app/invitation/[address]/page.tsx | 2 +- .../src/sections/settings/view.tsx | 67 +++++++++++++------ 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/infra/rooch-portal-v2/src/app/invitation/[address]/page.tsx b/infra/rooch-portal-v2/src/app/invitation/[address]/page.tsx index 3633c87c39..816468ce0d 100644 --- a/infra/rooch-portal-v2/src/app/invitation/[address]/page.tsx +++ b/infra/rooch-portal-v2/src/app/invitation/[address]/page.tsx @@ -1,6 +1,6 @@ import { InvitationsView } from 'src/sections/invitations/view'; -export const metadata = { title: `Srarch Invitation` }; +export const metadata = { title: `Search Invitation` }; export default function Page({ params }: { params: { address: string } }) { return ; diff --git a/infra/rooch-portal-v2/src/sections/settings/view.tsx b/infra/rooch-portal-v2/src/sections/settings/view.tsx index 3b8f274e9d..c8c868c1a2 100644 --- a/infra/rooch-portal-v2/src/sections/settings/view.tsx +++ b/infra/rooch-portal-v2/src/sections/settings/view.tsx @@ -92,6 +92,43 @@ export function SettingsView() { return loopFetchTwitterId(count +1) } + const checkTwitterObj = async (id: string) => { + const result = await client.queryObjectStates({ + filter: { + object_id: id + } + }) + + if (result.data.length === 0) { + await sleep(10000) + return checkTwitterObj(id) + } + + // TODO: twitter post btc address !== current wallet address. + // if (result.data[0].owner_bitcoin_address !== address?.toStr()) { + // throw (new Error('The twitter post btc address does not match the wallet address')) + // } + + return '' + } + const fetchTwitterPost = async (pureTweetId: string) => { + const res = await axios.post( + `${faucetUrl}/fetch-tweet`, + { + tweet_id: pureTweetId, + }, + { + headers: { + 'Content-Type': 'application/json', + }, + }, + ) + + if (res.data.ok) { + await checkTwitterObj(res.data.ok) + } + } + const disconnectTwitter = async () => { if (!session) { return @@ -168,26 +205,10 @@ export function SettingsView() { return } setVerifying(true) - const pureTweetId = match[1] try { const pureTweetId = match[1] - const res = await axios.post( - `${faucetUrl}/fetch-tweet`, - { - tweet_id: pureTweetId, - }, - { - headers: { - 'Content-Type': 'application/json', - }, - }, - ) - - if (!res.data.ok) { - toast.error('fetch twitter failed') - return - } + await fetchTwitterPost(pureTweetId) // step 2, check inviter const inviterAddr = window.localStorage.getItem(INVITER_ADDRESS_KEY) @@ -207,12 +228,14 @@ export function SettingsView() { } else { await bindTwitter(pureTweetId) } + } else { + await bindTwitter(pureTweetId) + } - await sleep(3000) - const checkRes = await loopFetchTwitterId() - if (checkRes) { - toast.success('Binding success') - } + await sleep(3000) + const checkRes = await loopFetchTwitterId() + if (checkRes) { + toast.success('Binding success') } } catch(error) { if ('response' in error) {