Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 2 additions & 59 deletions web-app/app/api/request-tokens/[...params]/route.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,2 @@
import { indexers, REQUEST_TYPES } from '@/constants'
import { walletBalanceLowSlackMessage } from '@/utils/slack'
import { balance, transfer } from '@autonomys/auto-consensus'
import { activateWallet, ActivateWalletParams, ApiPromise } from '@autonomys/auto-utils'
import { NextRequest, NextResponse } from 'next/server'

export const POST = async (req: NextRequest) => {
try {
if (!process.env.WALLET_CONSENSUS_URI) throw new Error('Missing WALLET_CONSENSUS_URI')
if (!process.env.CONSENSUS_AMOUNT && process.env.CONSENSUS_AMOUNT !== '0')
throw new Error('Missing CONSENSUS_AMOUNT')

const pathname = req.nextUrl.pathname
const chain = pathname.split('/').slice(3)[0]
const requestType = pathname.split('/').slice(4)[0]
if (requestType !== REQUEST_TYPES.Consensus)
return NextResponse.json({ error: 'Invalid request type' }, { status: 400 })

const chainMatch = indexers.find((c) => c.network === chain)
if (!chainMatch) return NextResponse.json({ error: 'Invalid chain' }, { status: 400 })

const request = await req.json()
const { address } = request

const {
api,
accounts: [wallet]
} = await activateWallet({
uri: process.env.WALLET_CONSENSUS_URI,
networkId: chainMatch.network
} as ActivateWalletParams)

// Get wallet free balance
const { free } = await balance(api as unknown as ApiPromise, wallet.address)
if (
BigInt(free) <
BigInt((Number(process.env.SLACK_BALANCE_NOTIFICATION_THRESHOLD) * Number(process.env.CONSENSUS_AMOUNT)) / 100)
) {
await walletBalanceLowSlackMessage(free.toString(), wallet.address)
}

if (BigInt(free) <= BigInt(process.env.CONSENSUS_AMOUNT))
return NextResponse.json({ error: 'Insufficient funds' }, { status: 400 })

// Create and sign the transfer transaction
const tx = await transfer(api as unknown as ApiPromise, address, process.env.CONSENSUS_AMOUNT)
const txResponse = await tx.signAndSend(wallet)

await api.disconnect()

return NextResponse.json({
message: 'Token requested successfully',
txResponse: { hash: txResponse.toString() }
})
} catch (error) {
console.error('Error processing token request:', error)
return NextResponse.json({ error: 'Failed to request token' }, { status: 500 })
}
}
// Removed: consensus chain request handler (single-chain EVM only)
export {}
35 changes: 2 additions & 33 deletions web-app/components/ConnectConsensusWallet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,2 @@
'use client'

import { cn } from '@/utils/cn'
import React, { useCallback, useState } from 'react'
import { PreferredExtensionModal } from './PreferredExtensionModal'

type ConnectConsensusWalletProps = {
className?: string
}

export const ConnectConsensusWallet: React.FC<ConnectConsensusWalletProps> = ({ className }) => {
const [isOpen, setIsOpen] = useState(false)

const onClick = useCallback((e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.preventDefault()
setIsOpen(true)
}, [])
const onClose = useCallback(() => setIsOpen(false), [])

return (
<>
<button
onClick={onClick}
className={cn(
'shadow bg-brand hover:bg-brand-hover text-white px-4 py-2 rounded-md cursor-pointer dark:bg-brand-secondary dark:hover:bg-brand-secondary-hover',
className
)}>
Connect Wallet
</button>
<PreferredExtensionModal isOpen={isOpen} onClose={onClose} />
</>
)
}
// Removed in single-chain mode
export {}
7 changes: 0 additions & 7 deletions web-app/components/ConnectWalletButton.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import { NetworkOptions, useNetworkStore } from '@/store/useStore'
import { useConnectModal } from '@rainbow-me/rainbowkit'
import { useEffect, useState } from 'react'
import { ConnectConsensusWallet } from './ConnectConsensusWallet'

export const ConnectWalletButton: React.FC = () => {
const [clientSide, setClientSide] = useState(false)
const { openConnectModal } = useConnectModal()
const { network } = useNetworkStore()

useEffect(() => {
setClientSide(true)
}, [])

if (!clientSide) return null

if (network === NetworkOptions.CONSENSUS) {
return <ConnectConsensusWallet className='text-sm py-1.5 px-3 border border-gray-100 dark:border-brand-hover' />
}

return (
<button
className='cursor-pointer flex text-sm items-center gap-2 px-3 py-1.5 border text-white border-gray-300 rounded-md shadow-sm bg-brand hover:bg-brand-hover dark:bg-brand-secondary dark:hover:bg-brand-secondary-hover dark:border-brand-hover'
Expand Down
4 changes: 1 addition & 3 deletions web-app/components/Discord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ export const Discord: React.FC<DiscordProps> = ({
<RequestTokenButton contract={contract} address={address} />
)}

{NetworkOptions.CONSENSUS === network && isDiscordGuildMember && address && (
<RequestTokenButton address={address} />
)}
{/* Single-chain mode: only EVM flow remains */}
</div>
</div>
</li>
Expand Down
8 changes: 1 addition & 7 deletions web-app/components/GitHub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ConnectWalletButton } from '@/components/ConnectWalletButton'
import { RequestTokenButton } from '@/components/RequestTokenButton'
import { Web2SocialButton } from '@/components/Web2SocialButton'
import { Contract } from '@/constants/contracts'
import { NetworkOptions, useNetworkStore } from '@/store/useStore'
import { Check, ExternalLink, Github } from 'lucide-react'
import Link from 'next/link'
import { useNetwork } from 'wagmi'
Expand All @@ -18,7 +17,6 @@ interface GitHubProps {
}

export const GitHub: React.FC<GitHubProps> = ({ isConnected, isGitHubFollower, contract, address, setActiveTab }) => {
const { network } = useNetworkStore()
const { chain } = useNetwork()
return (
<div className='space-y-6'>
Expand Down Expand Up @@ -101,13 +99,9 @@ export const GitHub: React.FC<GitHubProps> = ({ isConnected, isGitHubFollower, c
<div className='flex items-center justify-between'>
<p className='font-medium'>Request token</p>

{chain && network === NetworkOptions.AUTO_EVM && isGitHubFollower && address && contract && (
{chain && isGitHubFollower && address && contract && (
<RequestTokenButton contract={contract} address={address} />
)}

{NetworkOptions.CONSENSUS === network && isGitHubFollower && address && (
<RequestTokenButton address={address} />
)}
</div>
</div>
</li>
Expand Down
7 changes: 2 additions & 5 deletions web-app/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { NetworkOptions, useNetworkStore } from '@/store/useStore'
import Link from 'next/link'

export const Header: React.FC = () => {
const { network } = useNetworkStore()

const networkText = network === NetworkOptions.CONSENSUS ? 'Consensus' : 'Auto-EVM'
const networkText = 'Auto-EVM'

return (
<div className='mb-10 text-center'>
Expand All @@ -14,7 +11,7 @@ export const Header: React.FC = () => {
</p>
<Link href='https://docs.autonomys.network/mainnet/overview' target='_blank'>
<span className='inline-flex items-center rounded-full border border-gray-300 dark:border-gray-700 px-3 py-1 text-sm font-medium cursor-pointer'>
{networkText} - Autonomys Taurus Testnet
{networkText} Testnet
</span>
</Link>
</div>
Expand Down
26 changes: 4 additions & 22 deletions web-app/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
import { ConnectConsensusWallet } from '@/components/ConnectConsensusWallet'
import { ConnectEVMWallet } from '@/components/ConnectEVMWallet'
import useWallet from '@/hooks/useWallet'
import { NetworkOptions, useNetworkStore } from '@/store/useStore'
import { NetworkOptions } from '@/store/useStore'
import { useMemo } from 'react'
import AccountListDropdown from './ConnectConsensusWallet/AccountListDropdown'
import { LogoIcon } from './LogoIcon'
import NetworkDropdown from './NetworkDropdown'

export const Navbar: React.FC = () => {
const { network } = useNetworkStore()
const { actingAccount } = useWallet()

const walletsButton = useMemo(() => {
if (network === NetworkOptions.AUTO_EVM) {
return <ConnectEVMWallet />
}
if (actingAccount) {
return <AccountListDropdown />
}
return <ConnectConsensusWallet />
}, [network, actingAccount])
return <ConnectEVMWallet />
}, [])

return (
<header className='container mx-auto py-6 px-4 flex justify-between items-center'>
Expand All @@ -33,13 +21,7 @@ export const Navbar: React.FC = () => {
</div>
</div>
<div className='flex flex-row gap-3'>
<NetworkDropdown
options={[
{ label: 'Auto-EVM - Taurus', value: NetworkOptions.AUTO_EVM },
{ label: 'Consensus - Taurus', value: NetworkOptions.CONSENSUS }
]}
onSelect={() => {}}
/>
<NetworkDropdown options={[{ label: 'Auto-EVM', value: NetworkOptions.AUTO_EVM }]} onSelect={() => {}} />
{walletsButton}
</div>
</header>
Expand Down
58 changes: 22 additions & 36 deletions web-app/components/RequestTokenButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { ToastContent } from '@/components/ToastContent'
import { TokenRequested } from '@/components/TokenRequested'
import { Contract } from '@/constants/contracts'
import { NetworkOptions, useNetworkStore } from '@/store/useStore'
import { useNetworkStore } from '@/store/useStore'
import { formatSeconds } from '@/utils/time'
import { useSession } from 'next-auth/react'
import { useEffect, useState } from 'react'
Expand Down Expand Up @@ -87,47 +87,33 @@ export const RequestTokenButton: React.FC<RequestTokenButtonProps> = ({ contract
const handleRequestToken = async () => {
if (!validateSession()) return

// For Auto-EVM, check the timelock
if (network === NetworkOptions.AUTO_EVM && !checkTimeLock()) {
// Check the timelock
if (!checkTimeLock()) {
setIsError(true)
return
}
setIsLoading(true)
try {
let response
if (network === NetworkOptions.CONSENSUS) {
// Consensus network API call
response = await fetch(`/api/request-tokens/taurus/consensus`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ address })
})
} else {
// Check if chain is defined
if (!chain) {
toast.error(
<ToastContent title='Error requesting token' description='Network chain information is missing.' />
)
setIsError(true)
setIsLoading(false)
return
}
// Auto-EVM network API call
response = await fetch('/api/request-tokens', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chainId: chain.id,
address,
accountType: session?.user?.accountType,
accountId: session?.user?.id
})
})
// Check if chain is defined
if (!chain) {
toast.error(<ToastContent title='Error requesting token' description='Network chain information is missing.' />)
setIsError(true)
setIsLoading(false)
return
}
// Single EVM network API call
const response = await fetch('/api/request-tokens', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chainId: chain.id,
address,
accountType: session?.user?.accountType,
accountId: session?.user?.id
})
})

const result = await response.json()

Expand Down
21 changes: 4 additions & 17 deletions web-app/components/TokenCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { GitHub } from '@/components/GitHub'
import { NetworkSettings } from '@/components/NetworkSettings'
import { Terms } from '@/components/Terms'
import { contracts } from '@/constants/contracts'
import useWallet from '@/hooks/useWallet'
import { NetworkOptions, useNetworkStore } from '@/store/useStore'
import { FileText, Github, Settings } from 'lucide-react'
import { useSession } from 'next-auth/react'
Expand All @@ -18,7 +17,6 @@ export const TokenCard: React.FC = () => {
const { chain } = useNetwork()
const { data: session } = useSession()
const { network, activeTab, setActiveTab } = useNetworkStore()
const { actingAccount } = useWallet()

const contract = useMemo(() => {
if (chain && network === NetworkOptions.AUTO_EVM) {
Expand Down Expand Up @@ -56,24 +54,13 @@ export const TokenCard: React.FC = () => {
}, [])

const isWalletConnected = useMemo<boolean>(() => {
if (actingAccount && network === NetworkOptions.CONSENSUS) {
return true
}
if (isConnected && network === NetworkOptions.AUTO_EVM) {
return true
}
return false
}, [isConnected, actingAccount, network])
return !!isConnected
}, [isConnected])

const currentWalletAddress = useMemo(() => {
if (actingAccount && network === NetworkOptions.CONSENSUS) {
return actingAccount.address
}
if (isConnected && network === NetworkOptions.AUTO_EVM) {
return address
}
if (isConnected) return address
return ''
}, [actingAccount, network, address, isConnected])
}, [address, isConnected])

if (!clientSide) return null

Expand Down
4 changes: 2 additions & 2 deletions web-app/components/TokenRequested.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface TokenRequestedProps {
export const TokenRequested: React.FC<TokenRequestedProps> = ({ withdrawalAmount, chain, res }) => {
const { network } = useNetworkStore()

const AstralExplorerUrl = 'https://explorer.autonomys.xyz/taurus/consensus/extrinsics'
const AstralExplorerUrl = process.env.NEXT_PUBLIC_EXPLORER_URL || ''

return (
<div className='bg-brand-500 text-white px-4 py-2 w-[40vh]'>
Expand All @@ -41,7 +41,7 @@ export const TokenRequested: React.FC<TokenRequestedProps> = ({ withdrawalAmount
target='_blank'
rel='noopener noreferrer'>
<button className='border border-white text-white text-sm px-3 py-1 rounded hover:bg-brand-success-hover cursor-pointer'>
View on Autonomys Astral Explorer
View on Block Explorer
</button>
</a>
)}
Expand Down
Loading
Loading