-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frontend: Developed NetworkType component and placed it on top of the…
… wallet connect button. Improved styles of the ThemeSwitcher component.
- Loading branch information
Showing
5 changed files
with
79 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { useCurrentWallet } from '@mysten/dapp-kit' | ||
import { Badge } from '@radix-ui/themes' | ||
import c from 'clsx' | ||
import { useEffect, useState } from 'react' | ||
|
||
const CONNECTION_CHECK_DELAY = 2000 | ||
|
||
const DISCONNECTED_LABEL = 'disconnected' | ||
const MAINNET_LABEL = 'mainnet' | ||
|
||
const NetworkType = () => { | ||
const wallet = useCurrentWallet() | ||
const [networkName, setNetworkName] = useState<string>() | ||
|
||
// @todo Find a better type for the wallet. | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const connectionStatusCheck = (wallet: any) => { | ||
if (!wallet.isConnected) { | ||
setNetworkName(DISCONNECTED_LABEL) | ||
return | ||
} | ||
|
||
setNetworkName( | ||
prepareNetworkName(wallet.currentWallet?.accounts?.[0].chains?.[0]) | ||
) | ||
} | ||
|
||
useEffect(() => { | ||
const interval = setInterval( | ||
() => connectionStatusCheck(wallet), | ||
CONNECTION_CHECK_DELAY | ||
) | ||
return () => { | ||
clearTimeout(interval) | ||
} | ||
}, [wallet]) | ||
|
||
useEffect(() => { | ||
connectionStatusCheck(wallet) | ||
}, [wallet]) | ||
|
||
return ( | ||
<Badge | ||
className={c( | ||
'rounded-lg px-3 py-1.5 text-amber-600 shadow', | ||
{ '!text-red-500': networkName === DISCONNECTED_LABEL }, | ||
{ '!text-green-500': networkName === MAINNET_LABEL } | ||
)} | ||
> | ||
{networkName} | ||
</Badge> | ||
) | ||
} | ||
|
||
export default NetworkType | ||
|
||
const prepareNetworkName = (machineName: string) => { | ||
if (machineName.startsWith('sui:')) { | ||
return machineName.substring(4) | ||
} | ||
return machineName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters