Skip to content

Commit

Permalink
fix bugs (#3029)
Browse files Browse the repository at this point in the history
* fix bugs

* add loop check twitter obj
  • Loading branch information
wow-sven authored Dec 10, 2024
1 parent 5ef526a commit d024d08
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 46 deletions.
4 changes: 2 additions & 2 deletions infra/rooch-portal-v2/src/app/invitation/[address]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InvitationsView } from 'src/sections/invitations/index';
import { InvitationsView } from 'src/sections/invitations/view';

export const metadata = { title: `Invitation` };
export const metadata = { title: `Search Invitation` };

export default function Page({ params }: { params: { address: string } }) {
return <InvitationsView />;
Expand Down
8 changes: 0 additions & 8 deletions infra/rooch-portal-v2/src/app/invitation/page..tsx

This file was deleted.

11 changes: 11 additions & 0 deletions infra/rooch-portal-v2/src/app/invitation/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

import WalletGuard from 'src/components/guard/WalletGuard';
import InvitationOverviewView from 'src/sections/invitations/overview';

export const metadata = { title: `Invitation` };

export default function Page() {
return (<WalletGuard>
<InvitationOverviewView />
</WalletGuard>);
}
2 changes: 0 additions & 2 deletions infra/rooch-portal-v2/src/layouts/config-nav-dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ export const navData = [
title: 'Faucet',
path: paths.dashboard.faucet,
icon: <Iconify icon="solar:gift-bold-duotone" />,
// noAddressRequired: true,
},
{
title: 'Invitation',
path: paths.dashboard.invitation,
icon: <Iconify icon="solar:letter-broken" />,
// noAddressRequired: true,
},
{
title: 'Settings',
Expand Down
11 changes: 6 additions & 5 deletions infra/rooch-portal-v2/src/sections/faucet/inviter.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use client';

import type { Bytes} from '@roochnetwork/rooch-sdk';

import { useState, useEffect } from 'react';
import { Args, stringToBytes, toHEX, Bytes } from '@roochnetwork/rooch-sdk';
import { Args, toHEX, stringToBytes } from '@roochnetwork/rooch-sdk';
import {
useCurrentAddress,
useRoochClient,
useRoochClientQuery,
useCurrentWallet,
useCurrentAddress,
useRoochClientQuery,
} from '@roochnetwork/rooch-sdk-kit';

import { LoadingButton } from '@mui/lab';
Expand All @@ -17,12 +19,12 @@ import { useRouter } from 'src/routes/hooks';
import { useNetworkVariable } from 'src/hooks/use-networks';

import { formatCoin } from 'src/utils/format-number';
import { INVITER_ADDRESS_KEY } from 'src/utils/inviter';

import { DashboardContent } from 'src/layouts/dashboard';

import { toast } from 'src/components/snackbar';

import { INVITER_ADDRESS_KEY } from 'src/utils/inviter';
import { paths } from '../../routes/paths';

const FAUCET_NOT_OPEN = 'Faucet Not Open';
Expand Down Expand Up @@ -167,7 +169,6 @@ export function InviterFaucetView({ inviterAddress }: { inviterAddress: string }

if (!response.ok) {
const data = await response.json();
console.log(data);
if (response.status === 500 && data.error.includes('UTXO value is zero')) {
const msg = 'Claim failed, Not found UTXO';
setErrorMsg(msg);
Expand Down
17 changes: 14 additions & 3 deletions infra/rooch-portal-v2/src/sections/faucet/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useState, useEffect } from 'react';
import { Args, isValidBitcoinAddress } from '@roochnetwork/rooch-sdk';
import { useRoochClient, useRoochClientQuery } from '@roochnetwork/rooch-sdk-kit';
import { useCurrentNetwork, useRoochClient, useRoochClientQuery } from '@roochnetwork/rooch-sdk-kit';

import { LoadingButton } from '@mui/lab';
import { Box, Card, Chip, Stack, CardHeader, CardContent } from '@mui/material';
Expand All @@ -19,8 +19,9 @@ import { DashboardContent } from 'src/layouts/dashboard';

import { toast } from 'src/components/snackbar';

import { CopyToClipboard } from 'react-copy-to-clipboard'
import { paths } from '../../routes/paths'
import { INVITER_ADDRESS_KEY } from "../../utils/inviter";
import { INVITER_ADDRESS_KEY } from "../../utils/inviter"

const FAUCET_NOT_OPEN= 'Faucet Not Open'
const INVALID_UTXO = 'Invalid UTXO'
Expand All @@ -47,6 +48,7 @@ export function FaucetView({ address }: { address: string }) {
const faucetObject = useNetworkVariable('faucetObject');
const [claimGas, setClaimGas] = useState(0);
const router = useRouter();
const network = useCurrentNetwork()

useAddressChanged({ address, path: 'faucet' });

Expand Down Expand Up @@ -170,7 +172,16 @@ export function FaucetView({ address }: { address: string }) {
return (
<DashboardContent maxWidth="xl">
<Card>
<CardHeader title="Gas Faucet" sx={{ mb: 1 }} />
<Stack direction="row" alignItems="center" justifyContent="space-between" spacing={0.5} sx={{ width: '100%' }}>
<CardHeader title="Gas Faucet" sx={{ mb: 1, flex: 1 }} />
<Box sx={{mr:1.5}}>
<CopyToClipboard onCopy={() => {
toast.success('Copy to you clipboard')
}} text={`https://${network === 'mainnet' ? '':'test-'}portal.rooch.network/inviter/${viewAddress}`}>
<Chip className="justify-start w-fit" label="Share" />
</CopyToClipboard>
</Box>
</Stack>
<CardContent className="!pt-0">
<Stack spacing={2}>
<Stack direction="row" alignItems="center" spacing={0.5}>
Expand Down
20 changes: 20 additions & 0 deletions infra/rooch-portal-v2/src/sections/invitations/overview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client';

import { useEffect } from 'react';
import { useCurrentAddress } from '@roochnetwork/rooch-sdk-kit';

import { useRouter } from 'src/routes/hooks';

export default function InvitationOverviewView() {
const address = useCurrentAddress();
const router = useRouter();
useEffect(() => {
if (address) {
router.push(`/invitation/${address.toStr()}`);
}
}, [address, router]);
if (!address) {
return null;
}
return null;
}
86 changes: 60 additions & 26 deletions infra/rooch-portal-v2/src/sections/settings/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ export function SettingsView() {

const session = useCurrentSession()
const client = useRoochClient()
const wallet = useCurrentWallet()
const network = useCurrentNetwork()
const faucetUrl = useNetworkVariable('faucetUrl')
const twitterOracleAddress = useNetworkVariable('twitterOracleAddress')
const [inviterCA, inviterModule, inviterConf] = useNetworkVariable('inviterCA');
const wallet = useCurrentWallet()
const [tweetStatus, setTweetStatus] = useState('')
const [twitterId, setTwitterId] = useState<string>()
const [verifying, setVerifying] = useState(false)
const [fetchTwitterIdStatus, setFetchTwitterIdStatus] = useState(true)

const {
data: sessionKeys,
Expand Down Expand Up @@ -78,9 +79,56 @@ export function SettingsView() {
}, [address, client, twitterOracleAddress])

useEffect(() => {
fetchTwitterId()
fetchTwitterId().finally(() => setFetchTwitterIdStatus(false))
}, [fetchTwitterId])

const loopFetchTwitterId = async (count = 0) => {
const id = await fetchTwitterId()

if (id || count === 3) {
return id
}

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 @@ -157,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 @@ -196,12 +228,14 @@ export function SettingsView() {
} else {
await bindTwitter(pureTweetId)
}
} else {
await bindTwitter(pureTweetId)
}

await sleep(3000)
const checkRes = await fetchTwitterId()
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 All @@ -218,7 +252,7 @@ export function SettingsView() {
}
}

const networkText = network === 'mainnet' ? 'Pre-mainnet' : 'Testnet'
const networkText = network === 'mainnet' ? 'PreMainnet' : 'Testnet'
const XText = `BTC:${address?.toStr()}
Rooch ${networkText} is live! Bind your Twitter to earn RGas, and visit https://${network === 'mainnet' ? '':'test-'}grow.rooch.network to earn rewards with your BTC.
Expand Down Expand Up @@ -256,7 +290,7 @@ https://${network === 'mainnet' ? '':'test-'}portal.rooch.network/inviter/${addr
subheader="Bind a Twitter account to a Bitcoin address via publishing a tweet"
/>
<CardContent className="!pt-2">
{twitterId ? (
{fetchTwitterIdStatus ? <></>: twitterId ? (
<Stack className="mt-2" spacing={1.5} alignItems="flex-start">
<Chip
className="justify-start w-fit"
Expand Down

0 comments on commit d024d08

Please sign in to comment.