Skip to content

Commit

Permalink
add loop check twitter obj
Browse files Browse the repository at this point in the history
  • Loading branch information
wow-sven committed Dec 10, 2024
1 parent d45a975 commit e75a447
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -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 <InvitationsView />;
Expand Down
67 changes: 45 additions & 22 deletions infra/rooch-portal-v2/src/sections/settings/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit e75a447

Please sign in to comment.