diff --git a/packages/state/recoil/selectors/token.ts b/packages/state/recoil/selectors/token.ts index da403d08d..46a1454ca 100644 --- a/packages/state/recoil/selectors/token.ts +++ b/packages/state/recoil/selectors/token.ts @@ -125,9 +125,8 @@ export const usdPriceSelector = selectorFamily< case ChainId.JunoMainnet: return get(wyndUsdPriceSelector(denomOrAddress)) case ChainId.OsmosisMainnet: - // TODO(stargaze): get osmosis denoms for stargaze assets - case ChainId.StargazeMainnet: return get(osmosisUsdPriceSelector(denomOrAddress)) + // TODO(stargaze): get osmosis denoms for stargaze assets } }, }) diff --git a/packages/stateful/command/components/CommandModal.tsx b/packages/stateful/command/components/CommandModal.tsx index d14be2d65..9f750b94e 100644 --- a/packages/stateful/command/components/CommandModal.tsx +++ b/packages/stateful/command/components/CommandModal.tsx @@ -25,12 +25,18 @@ export const CommandModal = ({ // and each useSections hook is different, we need to tell the component to // re-render as if it's a new component. const [contextChangeCount, setContextChangeCount] = useState(0) - const setContexts: typeof _setContexts = useCallback((...args) => { - setContextChangeCount((count) => count + 1) - _setContexts(...args) - // Focus input when adding new context. - searchBarRef.current?.focus() - }, []) + const setContexts: typeof _setContexts = useCallback( + (...args) => { + setContextChangeCount((count) => count + 1) + _setContexts(...args) + + // Focus input when adding new context if visible. + if (props.visible) { + searchBarRef.current?.focus() + } + }, + [props.visible] + ) // Reset with new root context whenever makeRootContext changes. Also // initializes first time. diff --git a/packages/stateful/hooks/useWallet.ts b/packages/stateful/hooks/useWallet.ts index d370b0863..283162138 100644 --- a/packages/stateful/hooks/useWallet.ts +++ b/packages/stateful/hooks/useWallet.ts @@ -1,12 +1,7 @@ import { Chain } from '@chain-registry/types' import { toHex } from '@cosmjs/encoding' -import { - ChainContext, - ChainWalletContext, - WalletAccount, -} from '@cosmos-kit/core' +import { ChainContext, WalletAccount } from '@cosmos-kit/core' import { useChain } from '@cosmos-kit/react-lite' -import { getChainWalletContext } from '@cosmos-kit/react-lite/cjs/utils' import { useEffect, useMemo, useRef, useState } from 'react' import { useRecoilValue } from 'recoil' @@ -47,43 +42,21 @@ export const useWallet = ({ ? getChainForChainId(chainId) : currentChain || getChainForChainId(walletChainId) - // Make sure to enable chain on currently connected wallet. - // TODO this is hacky cosmos-kit should have a better solution - const connectedWallet = useChain(getChainForChainId(walletChainId).chain_name) - const chainWallet = connectedWallet.chainWallet?.mainWallet.getChainWallet( - chain.chain_name - ) - chainWallet?.activate() - - // Only try to connect once per wallet address. If address changes, try to - // connect again. - const triedToConnect = useRef(undefined) - if ( - connectedWallet.isWalletConnected && - chainWallet && - !chainWallet.isWalletConnected && - (!triedToConnect.current || - triedToConnect.current === connectedWallet.address) - ) { - triedToConnect.current = connectedWallet.address - chainWallet.connect().catch(console.error) - } + const _walletChain = useChain(chain.chain_name) // Memoize wallet chain since it changes every render. The hook above forces // re-render when address changes, so this is safe. - const walletChainRef = useRef(undefined) - walletChainRef.current = chainWallet - ? getChainWalletContext(chain.chain_id, chainWallet) - : undefined + const walletChainRef = useRef(_walletChain) + walletChainRef.current = _walletChain const [account, setAccount] = useState() const [hexPublicKeyData, setHexPublicKeyData] = useState() const hexPublicKeyFromChain = useCachedLoading( - walletChainRef.current?.address && loadAccount + _walletChain.address && loadAccount ? walletHexPublicKeySelector({ - walletAddress: walletChainRef.current.address, - chainId: walletChainRef.current.chain.chain_id, + walletAddress: _walletChain.address, + chainId: _walletChain.chain.chain_id, }) : undefined, undefined @@ -94,7 +67,7 @@ export const useWallet = ({ return } - if (!walletChainRef.current?.isWalletConnected) { + if (!walletChainRef.current.isWalletConnected) { setAccount(undefined) setHexPublicKeyData(undefined) return @@ -104,7 +77,7 @@ export const useWallet = ({ if (account?.address !== walletChainRef.current.address) { ;(async () => { try { - const account = await walletChainRef.current?.getAccount() + const account = await walletChainRef.current.getAccount() setAccount(account) setHexPublicKeyData(account && toHex(account.pubkey)) } catch (err) { @@ -115,14 +88,13 @@ export const useWallet = ({ }, [ account?.address, loadAccount, - walletChainRef.current?.address, - walletChainRef.current?.chain.chain_id, - walletChainRef.current?.status, + walletChainRef.current.address, + walletChainRef.current.chain.chain_id, + walletChainRef.current.status, ]) const response = useMemo( (): UseWalletReturn => ({ - ...connectedWallet, ...walletChainRef.current, // Use chain from our version of the chain-registry. chain, diff --git a/packages/stateless/components/inputs/ImageSelector.tsx b/packages/stateless/components/inputs/ImageSelector.tsx index e6f8a7cdc..75f74ada2 100644 --- a/packages/stateless/components/inputs/ImageSelector.tsx +++ b/packages/stateless/components/inputs/ImageSelector.tsx @@ -104,7 +104,7 @@ export const ImageSelectorModal = < { diff --git a/packages/stateless/components/modals/NftSelectionModal.tsx b/packages/stateless/components/modals/NftSelectionModal.tsx index e8724619a..02ef77060 100644 --- a/packages/stateless/components/modals/NftSelectionModal.tsx +++ b/packages/stateless/components/modals/NftSelectionModal.tsx @@ -212,7 +212,7 @@ export const NftSelectionModal = ({ {headerDisplay} diff --git a/packages/stateless/components/modals/TokenDepositModal.tsx b/packages/stateless/components/modals/TokenDepositModal.tsx index 50be84dc5..26917cef2 100644 --- a/packages/stateless/components/modals/TokenDepositModal.tsx +++ b/packages/stateless/components/modals/TokenDepositModal.tsx @@ -111,7 +111,7 @@ export const TokenDepositModal = ({