Skip to content

Commit d85af7a

Browse files
Merge pull request #117 from autonomys/fix-default-contract-Consensus
fix(ui): 🐛 request token button permission for consenses network
2 parents fd8df33 + fc0f655 commit d85af7a

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

web-app/components/Discord.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { ConnectWalletButton } from '@/components/ConnectWalletButton'
22
import { RequestTokenButton } from '@/components/RequestTokenButton'
33
import { Web2SocialButton } from '@/components/Web2SocialButton'
44
import { Contract } from '@/constants/contracts'
5+
import { NetworkOptions, useNetworkStore } from '@/store/useStore'
56
import { Check, ExternalLink } from 'lucide-react'
67
import Link from 'next/link'
78
import { RxDiscordLogo } from 'react-icons/rx'
9+
import { useNetwork } from 'wagmi'
810

911
interface DiscordProps {
1012
isConnected: boolean
@@ -21,6 +23,8 @@ export const Discord: React.FC<DiscordProps> = ({
2123
address,
2224
setActiveTab
2325
}) => {
26+
const { network } = useNetworkStore()
27+
const { chain } = useNetwork()
2428
return (
2529
<div className='space-y-6'>
2630
<h3 className='text-xl font-semibold mb-4'>Request token via Discord</h3>
@@ -100,7 +104,14 @@ export const Discord: React.FC<DiscordProps> = ({
100104
<div className='flex-1 pt-1'>
101105
<div className='flex items-center justify-between'>
102106
<p className='font-medium'>Request token with the Faucet bot on Discord or here</p>
103-
{contract && address && <RequestTokenButton contract={contract} address={address} />}
107+
108+
{chain && network === NetworkOptions.AUTO_EVM && address && isDiscordGuildMember && contract && (
109+
<RequestTokenButton contract={contract} address={address} />
110+
)}
111+
112+
{NetworkOptions.CONSENSUS === network && isDiscordGuildMember && address && (
113+
<RequestTokenButton address={address} />
114+
)}
104115
</div>
105116
</div>
106117
</li>

web-app/components/GitHub.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import { ConnectWalletButton } from '@/components/ConnectWalletButton'
44
import { RequestTokenButton } from '@/components/RequestTokenButton'
55
import { Web2SocialButton } from '@/components/Web2SocialButton'
66
import { Contract } from '@/constants/contracts'
7+
import { NetworkOptions, useNetworkStore } from '@/store/useStore'
78
import { Check, ExternalLink, Github } from 'lucide-react'
89
import Link from 'next/link'
10+
import { useNetwork } from 'wagmi'
911

1012
interface GitHubProps {
1113
isConnected: boolean
@@ -16,6 +18,8 @@ interface GitHubProps {
1618
}
1719

1820
export const GitHub: React.FC<GitHubProps> = ({ isConnected, isGitHubFollower, contract, address, setActiveTab }) => {
21+
const { network } = useNetworkStore()
22+
const { chain } = useNetwork()
1923
return (
2024
<div className='space-y-6'>
2125
<h3 className='text-xl font-semibold mb-4'>Request token via GitHub</h3>
@@ -96,7 +100,14 @@ export const GitHub: React.FC<GitHubProps> = ({ isConnected, isGitHubFollower, c
96100
<div className='flex-1 pt-1'>
97101
<div className='flex items-center justify-between'>
98102
<p className='font-medium'>Request token</p>
99-
{contract && address && <RequestTokenButton contract={contract} address={address} />}
103+
104+
{chain && network === NetworkOptions.AUTO_EVM && isGitHubFollower && address && contract && (
105+
<RequestTokenButton contract={contract} address={address} />
106+
)}
107+
108+
{NetworkOptions.CONSENSUS === network && isGitHubFollower && address && (
109+
<RequestTokenButton address={address} />
110+
)}
100111
</div>
101112
</div>
102113
</li>

web-app/components/RequestTokenButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { toast } from 'react-toastify'
1212
import { useContractReads, useNetwork } from 'wagmi'
1313

1414
interface RequestTokenButtonProps {
15-
contract: Contract
15+
contract?: Contract
1616
address: string
1717
}
1818

web-app/components/TokenCard.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@ import { useAccount, useNetwork } from 'wagmi'
1414

1515
export const TokenCard: React.FC = () => {
1616
const [clientSide, setClientSide] = useState(false)
17-
const [activeTab, setActiveTab] = useState('github')
1817
const { isConnected, address } = useAccount()
1918
const { chain } = useNetwork()
2019
const { data: session } = useSession()
21-
const { network } = useNetworkStore()
20+
const { network, activeTab, setActiveTab } = useNetworkStore()
2221
const { actingAccount } = useWallet()
2322

24-
const contract = useMemo(() => chain && contracts.find((c) => c.name === 'Faucet' && c.chainId === chain.id), [chain])
23+
const contract = useMemo(() => {
24+
if (chain && network === NetworkOptions.AUTO_EVM) {
25+
return contracts.find((c) => c.name === 'Faucet' && c.chainId === chain.id)
26+
}
27+
return undefined
28+
}, [chain, network])
29+
2530
const isGitHubFollower = useMemo(
2631
() => !!(session && session.user != null && session.user.isGitHubFollower),
2732
[session]

web-app/store/useStore.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ interface NetworkState {
1414
networks: Network[]
1515
version: number
1616
setNetworks: (networks: Network[]) => void
17+
activeTab: string
18+
setActiveTab: (tab: string) => void
1719
}
1820

1921
export const useNetworkStore = create<NetworkState>()(
@@ -23,7 +25,9 @@ export const useNetworkStore = create<NetworkState>()(
2325
setNetwork: (network: NetworkOptions) => set({ network }),
2426
networks: networks,
2527
version: 1,
26-
setNetworks: (networks: Network[]) => set({ networks })
28+
setNetworks: (networks: Network[]) => set({ networks }),
29+
activeTab: 'github',
30+
setActiveTab: (tab: string) => set({ activeTab: tab })
2731
}),
2832
{
2933
name: 'network-storage',

0 commit comments

Comments
 (0)