99 useColorModeValue ,
1010 Text
1111} from '@chakra-ui/react' ;
12- import { MouseEventHandler , useMemo } from 'react' ;
12+ import { MouseEventHandler , useEffect } from 'react' ;
1313import { FiAlertTriangle } from 'react-icons/fi' ;
1414import {
1515 Astronaut ,
@@ -27,9 +27,8 @@ import {
2727 WalletConnectComponent ,
2828 ChainCard
2929} from '../components' ;
30- import { getWalletPrettyName } from '@cosmos-kit/config' ;
31- import { assets as chainAssets } from 'chain-registry' ;
32- import { ChainRecord } from '@cosmos-kit/core' ;
30+ import { chainName } from '../config' ;
31+
3332
3433export const WalletSection = ( ) => {
3534 const walletManager = useWallet ( ) ;
@@ -41,32 +40,22 @@ export const WalletSection = () => {
4140 address,
4241 message,
4342 currentChainName,
44- currentWalletName,
45- chains
43+ currentWallet,
44+ currentChainRecord,
45+ getChainLogo,
46+ setCurrentChain
4647 } = walletManager ;
4748
48- const chainName = currentChainName ;
49+ useEffect ( ( ) => {
50+ setCurrentChain ( chainName ) ;
51+ } , [ setCurrentChain ] ) ;
4952
50- const chain = useMemo (
51- ( ) => {
52- const getChain = ( chainRecord : ChainRecord ) => {
53- const assets = chainAssets . find (
54- ( _chain ) => _chain . chain_name === chainRecord . name
55- ) ?. assets ;
56- return {
57- chainName : chainRecord . name ,
58- label : chainRecord . chain . pretty_name ,
59- value : chainRecord . name ,
60- icon : assets
61- ? assets [ 0 ] ?. logo_URIs ?. svg || assets [ 0 ] ?. logo_URIs ?. png
62- : undefined ,
63- disabled : false
64- } ;
65- }
66- return getChain ( chains [ 0 ] ) ;
67- } ,
68- [ chains ]
69- ) ;
53+ const chain = {
54+ chainName : currentChainName ,
55+ label : currentChainRecord ?. chain . pretty_name ,
56+ value : currentChainName ,
57+ icon : getChainLogo ( currentChainName )
58+ }
7059
7160 // Events
7261 const onClickConnect : MouseEventHandler = async ( e ) => {
@@ -104,17 +93,13 @@ export const WalletSection = () => {
10493 rejected = {
10594 < RejectedWarn
10695 icon = { < Icon as = { FiAlertTriangle } mt = { 1 } /> }
107- wordOfWarning = { `${ getWalletPrettyName (
108- currentWalletName
109- ) } : ${ message } `}
96+ wordOfWarning = { `${ currentWallet ?. walletInfo . prettyName } : ${ message } ` }
11097 />
11198 }
11299 error = {
113100 < RejectedWarn
114101 icon = { < Icon as = { FiAlertTriangle } mt = { 1 } /> }
115- wordOfWarning = { `${ getWalletPrettyName (
116- currentWalletName
117- ) } : ${ message } `}
102+ wordOfWarning = { `${ currentWallet ?. walletInfo . prettyName } : ${ message } ` }
118103 />
119104 }
120105 />
@@ -123,7 +108,7 @@ export const WalletSection = () => {
123108 const userInfo = (
124109 < ConnectedUserInfo username = { username } icon = { < Astronaut /> } />
125110 ) ;
126- const addressBtn = chainName && (
111+ const addressBtn = currentChainName && (
127112 < CopyAddressBtn
128113 walletStatus = { walletStatus }
129114 connected = { < ConnectedShowAddress address = { address } isLoading = { false } /> }
@@ -140,10 +125,10 @@ export const WalletSection = () => {
140125 alignItems = "center"
141126 justifyContent = "center"
142127 >
143- { chainName && (
128+ { currentChainName && (
144129 < GridItem marginBottom = { '20px' } >
145130 < ChainCard
146- prettyName = { chain ?. label || chainName }
131+ prettyName = { chain ?. label || currentChainName }
147132 icon = { chain ?. icon }
148133 />
149134 </ GridItem >
0 commit comments