Skip to content

Commit e59a667

Browse files
committed
Simplify WebUI setup
1 parent c0c6ebc commit e59a667

File tree

8 files changed

+32
-158
lines changed

8 files changed

+32
-158
lines changed
Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,2 @@
1-
import { indexers, REQUEST_TYPES } from '@/constants'
2-
import { walletBalanceLowSlackMessage } from '@/utils/slack'
3-
import { balance, transfer } from '@autonomys/auto-consensus'
4-
import { activateWallet, ActivateWalletParams, ApiPromise } from '@autonomys/auto-utils'
5-
import { NextRequest, NextResponse } from 'next/server'
6-
7-
export const POST = async (req: NextRequest) => {
8-
try {
9-
if (!process.env.WALLET_CONSENSUS_URI) throw new Error('Missing WALLET_CONSENSUS_URI')
10-
if (!process.env.CONSENSUS_AMOUNT && process.env.CONSENSUS_AMOUNT !== '0')
11-
throw new Error('Missing CONSENSUS_AMOUNT')
12-
13-
const pathname = req.nextUrl.pathname
14-
const chain = pathname.split('/').slice(3)[0]
15-
const requestType = pathname.split('/').slice(4)[0]
16-
if (requestType !== REQUEST_TYPES.Consensus)
17-
return NextResponse.json({ error: 'Invalid request type' }, { status: 400 })
18-
19-
const chainMatch = indexers.find((c) => c.network === chain)
20-
if (!chainMatch) return NextResponse.json({ error: 'Invalid chain' }, { status: 400 })
21-
22-
const request = await req.json()
23-
const { address } = request
24-
25-
const {
26-
api,
27-
accounts: [wallet]
28-
} = await activateWallet({
29-
uri: process.env.WALLET_CONSENSUS_URI,
30-
networkId: chainMatch.network
31-
} as ActivateWalletParams)
32-
33-
// Get wallet free balance
34-
const { free } = await balance(api as unknown as ApiPromise, wallet.address)
35-
if (
36-
BigInt(free) <
37-
BigInt((Number(process.env.SLACK_BALANCE_NOTIFICATION_THRESHOLD) * Number(process.env.CONSENSUS_AMOUNT)) / 100)
38-
) {
39-
await walletBalanceLowSlackMessage(free.toString(), wallet.address)
40-
}
41-
42-
if (BigInt(free) <= BigInt(process.env.CONSENSUS_AMOUNT))
43-
return NextResponse.json({ error: 'Insufficient funds' }, { status: 400 })
44-
45-
// Create and sign the transfer transaction
46-
const tx = await transfer(api as unknown as ApiPromise, address, process.env.CONSENSUS_AMOUNT)
47-
const txResponse = await tx.signAndSend(wallet)
48-
49-
await api.disconnect()
50-
51-
return NextResponse.json({
52-
message: 'Token requested successfully',
53-
txResponse: { hash: txResponse.toString() }
54-
})
55-
} catch (error) {
56-
console.error('Error processing token request:', error)
57-
return NextResponse.json({ error: 'Failed to request token' }, { status: 500 })
58-
}
59-
}
1+
// Removed: consensus chain request handler (single-chain EVM only)
2+
export {}
Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,2 @@
1-
'use client'
2-
3-
import { cn } from '@/utils/cn'
4-
import React, { useCallback, useState } from 'react'
5-
import { PreferredExtensionModal } from './PreferredExtensionModal'
6-
7-
type ConnectConsensusWalletProps = {
8-
className?: string
9-
}
10-
11-
export const ConnectConsensusWallet: React.FC<ConnectConsensusWalletProps> = ({ className }) => {
12-
const [isOpen, setIsOpen] = useState(false)
13-
14-
const onClick = useCallback((e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
15-
e.preventDefault()
16-
setIsOpen(true)
17-
}, [])
18-
const onClose = useCallback(() => setIsOpen(false), [])
19-
20-
return (
21-
<>
22-
<button
23-
onClick={onClick}
24-
className={cn(
25-
'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',
26-
className
27-
)}>
28-
Connect Wallet
29-
</button>
30-
<PreferredExtensionModal isOpen={isOpen} onClose={onClose} />
31-
</>
32-
)
33-
}
1+
// Removed in single-chain mode
2+
export {}

web-app/components/ConnectWalletButton.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { NetworkOptions, useNetworkStore } from '@/store/useStore'
22
import { useConnectModal } from '@rainbow-me/rainbowkit'
33
import { useEffect, useState } from 'react'
4-
import { ConnectConsensusWallet } from './ConnectConsensusWallet'
54

65
export const ConnectWalletButton: React.FC = () => {
76
const [clientSide, setClientSide] = useState(false)
@@ -14,10 +13,6 @@ export const ConnectWalletButton: React.FC = () => {
1413

1514
if (!clientSide) return null
1615

17-
if (network === NetworkOptions.CONSENSUS) {
18-
return <ConnectConsensusWallet className='text-sm py-1.5 px-3 border border-gray-100 dark:border-brand-hover' />
19-
}
20-
2116
return (
2217
<button
2318
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'

web-app/components/Discord.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ export const Discord: React.FC<DiscordProps> = ({
109109
<RequestTokenButton contract={contract} address={address} />
110110
)}
111111

112-
{NetworkOptions.CONSENSUS === network && isDiscordGuildMember && address && (
113-
<RequestTokenButton address={address} />
114-
)}
112+
{/* Single-chain mode: only EVM flow remains */}
115113
</div>
116114
</div>
117115
</li>

web-app/components/GitHub.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,9 @@ export const GitHub: React.FC<GitHubProps> = ({ isConnected, isGitHubFollower, c
101101
<div className='flex items-center justify-between'>
102102
<p className='font-medium'>Request token</p>
103103

104-
{chain && network === NetworkOptions.AUTO_EVM && isGitHubFollower && address && contract && (
104+
{chain && isGitHubFollower && address && contract && (
105105
<RequestTokenButton contract={contract} address={address} />
106106
)}
107-
108-
{NetworkOptions.CONSENSUS === network && isGitHubFollower && address && (
109-
<RequestTokenButton address={address} />
110-
)}
111107
</div>
112108
</div>
113109
</li>

web-app/components/RequestTokenButton.tsx

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -87,47 +87,33 @@ export const RequestTokenButton: React.FC<RequestTokenButtonProps> = ({ contract
8787
const handleRequestToken = async () => {
8888
if (!validateSession()) return
8989

90-
// For Auto-EVM, check the timelock
91-
if (network === NetworkOptions.AUTO_EVM && !checkTimeLock()) {
90+
// Check the timelock
91+
if (!checkTimeLock()) {
9292
setIsError(true)
9393
return
9494
}
9595
setIsLoading(true)
9696
try {
97-
let response
98-
if (network === NetworkOptions.CONSENSUS) {
99-
// Consensus network API call
100-
response = await fetch(`/api/request-tokens/taurus/consensus`, {
101-
method: 'POST',
102-
headers: {
103-
'Content-Type': 'application/json'
104-
},
105-
body: JSON.stringify({ address })
106-
})
107-
} else {
108-
// Check if chain is defined
109-
if (!chain) {
110-
toast.error(
111-
<ToastContent title='Error requesting token' description='Network chain information is missing.' />
112-
)
113-
setIsError(true)
114-
setIsLoading(false)
115-
return
116-
}
117-
// Auto-EVM network API call
118-
response = await fetch('/api/request-tokens', {
119-
method: 'POST',
120-
headers: {
121-
'Content-Type': 'application/json'
122-
},
123-
body: JSON.stringify({
124-
chainId: chain.id,
125-
address,
126-
accountType: session?.user?.accountType,
127-
accountId: session?.user?.id
128-
})
129-
})
97+
// Check if chain is defined
98+
if (!chain) {
99+
toast.error(<ToastContent title='Error requesting token' description='Network chain information is missing.' />)
100+
setIsError(true)
101+
setIsLoading(false)
102+
return
130103
}
104+
// Single EVM network API call
105+
const response = await fetch('/api/request-tokens', {
106+
method: 'POST',
107+
headers: {
108+
'Content-Type': 'application/json'
109+
},
110+
body: JSON.stringify({
111+
chainId: chain.id,
112+
address,
113+
accountType: session?.user?.accountType,
114+
accountId: session?.user?.id
115+
})
116+
})
131117

132118
const result = await response.json()
133119

web-app/components/TokenCard.tsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,13 @@ export const TokenCard: React.FC = () => {
5656
}, [])
5757

5858
const isWalletConnected = useMemo<boolean>(() => {
59-
if (actingAccount && network === NetworkOptions.CONSENSUS) {
60-
return true
61-
}
62-
if (isConnected && network === NetworkOptions.AUTO_EVM) {
63-
return true
64-
}
65-
return false
66-
}, [isConnected, actingAccount, network])
59+
return !!isConnected
60+
}, [isConnected])
6761

6862
const currentWalletAddress = useMemo(() => {
69-
if (actingAccount && network === NetworkOptions.CONSENSUS) {
70-
return actingAccount.address
71-
}
72-
if (isConnected && network === NetworkOptions.AUTO_EVM) {
73-
return address
74-
}
63+
if (isConnected) return address
7564
return ''
76-
}, [actingAccount, network, address, isConnected])
65+
}, [address, isConnected])
7766

7867
if (!clientSide) return null
7968

web-app/constants/routes.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export enum REQUEST_TYPES {
2-
Consensus = 'consensus'
3-
}
1+
export {}

0 commit comments

Comments
 (0)