diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 00000000..351d0682 Binary files /dev/null and b/bun.lockb differ diff --git a/components/Icons/KeplrWalletIcon.tsx b/components/Icons/KeplrWalletIcon.tsx deleted file mode 100644 index 518b3655..00000000 --- a/components/Icons/KeplrWalletIcon.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import * as React from 'react' - -export default function KeplrWalletIcon() { - return ( - - - - - - - - - - ) -} diff --git a/components/Icons/LeapSnapIcon.tsx b/components/Icons/LeapSnapIcon.tsx deleted file mode 100644 index 9b05bed1..00000000 --- a/components/Icons/LeapSnapIcon.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import * as React from 'react' - -export default function LeapWalletIcon() { - return ( - - ) -} diff --git a/components/Icons/LeapWalletIcon.tsx b/components/Icons/LeapWalletIcon.tsx deleted file mode 100644 index 6442d009..00000000 --- a/components/Icons/LeapWalletIcon.tsx +++ /dev/null @@ -1,66 +0,0 @@ -import * as React from 'react' - -export default function LeapWalletIcon() { - return ( - - - - - - - - - - - - - - - - - - - - - - - - ) -} diff --git a/components/Icons/TerraExtensionIcon.tsx b/components/Icons/TerraExtensionIcon.tsx deleted file mode 100644 index 50a63269..00000000 --- a/components/Icons/TerraExtensionIcon.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import * as React from 'react' - -export default function TerraExtensionIcon() { - return ( - - - - - - - - - - ) -} diff --git a/components/Icons/TerraStationWalletIcon.tsx b/components/Icons/TerraStationWalletIcon.tsx deleted file mode 100644 index 7dea7804..00000000 --- a/components/Icons/TerraStationWalletIcon.tsx +++ /dev/null @@ -1 +0,0 @@ -export const TerraStationWalletIcon = () => () diff --git a/components/Layout/AppLayout.tsx b/components/Layout/AppLayout.tsx index 68c3448e..c856632a 100644 --- a/components/Layout/AppLayout.tsx +++ b/components/Layout/AppLayout.tsx @@ -1,4 +1,4 @@ -import { FC, ReactNode, useMemo } from 'react' +import { type PropsWithChildren, useMemo } from 'react' import { isMobile } from 'react-device-detect' import { useMediaQuery, Flex } from '@chakra-ui/react' @@ -10,12 +10,13 @@ import Status from '../Status' import MobileNotSupportedModal from '../Wallet/Modal/MobileNotSupportedModal' import RadialGradient, { backgrounds } from './RadialGradient' -const AppLayout: FC = ({ children }) => { +const AppLayout = ({ children }: PropsWithChildren) => { const { chainId } = useRecoilValue(chainState) const [isMobileView] = useMediaQuery('(max-width: 480px)') const mobileBrowserLeap = window.leap && window.leap.mode === 'mobile-web' const mobileBrowserKeplr = window.keplr && window.keplr.mode === 'mobile-web' const background = useMemo(() => backgrounds[chainId], [chainId]) + return ( <> {isMobile &&
{ const { chainId, chainName, network, walletChainName } = useRecoilValue(chainState) - const { isWalletConnected, address } = useChain(walletChainName) + const { address } = useChain(walletChainName) + const { connected } = useConnect() const data: BondingData[] = [ { @@ -162,7 +163,7 @@ const Bonding: FC = () => { setWithdrawableTokens(withdrawableInfos) setData(data) }, [ - isWalletConnected, + connected, isLoading, unbondingRequests, myBondedAssets, @@ -171,7 +172,7 @@ const Bonding: FC = () => { symbols, ]) const { isOpen, onOpen, onClose } = useDisclosure() - return <>{isLoading && isWalletConnected ? + return <>{isLoading && connected ? { { xl: 'end', }}> { const [isMobile] = useMediaQuery('(max-width: 720px)') const [currentBondState, setCurrentBondState] = useRecoilState(bondingState) - const { network, chainId, walletChainName } = useRecoilValue(chainState) - const { isWalletConnected } = useChain(walletChainName) + const { network, chainId } = useRecoilValue(chainState) + const { connected } = useConnect() const [tokenBalances, setTokenBalances] = useState(null) @@ -60,7 +60,7 @@ export const Bond = ({ balances, tokenSymbols }) => { denom: config.bonding_tokens[0].denom, }) } - }, [isWalletConnected, config]) + }, [connected, config]) const { control } = useForm({ mode: 'onChange', diff --git a/components/Pages/Bonding/BondingActions/BondingActions.tsx b/components/Pages/Bonding/BondingActions/BondingActions.tsx index b42cacf9..2f8e590c 100644 --- a/components/Pages/Bonding/BondingActions/BondingActions.tsx +++ b/components/Pages/Bonding/BondingActions/BondingActions.tsx @@ -2,7 +2,7 @@ import { useMemo } from 'react' import { ArrowBackIcon } from '@chakra-ui/icons' import { Box, Button, HStack, IconButton, Text, VStack } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain, useConnect } from '@quirks/react' import Loader from 'components/Loader' import { Bond, BondingTokenState } from 'components/Pages/Bonding/BondingActions/Bond' import { bondingAtom } from 'components/Pages/Bonding/BondingActions/bondAtoms' @@ -19,6 +19,7 @@ import { } from 'components/Pages/Bonding/hooks/useDashboardData' import { kBg, kBorderRadius } from 'constants/visualComponentConstants' import { useMultipleTokenBalance } from 'hooks/useTokenBalance' +import { useWalletModal } from 'hooks/useWalletModal' import { useRouter } from 'next/router' import { useRecoilState, useRecoilValue } from 'recoil' import { chainState } from 'state/chainState' @@ -26,7 +27,9 @@ import { TxStep } from 'types/index' const BondingActions = ({ globalAction }) => { const { chainId, network, chainName, walletChainName } = useRecoilValue(chainState) - const { address, isWalletConnected, openView } = useChain(walletChainName) + const { address } = useChain(walletChainName) + const { connected } = useConnect() + const { openModal } = useWalletModal() const router = useRouter() @@ -57,7 +60,7 @@ const BondingActions = ({ globalAction }) => { 0) const buttonLabel = useMemo(() => { - if (!isWalletConnected) { + if (!connected) { return 'Connect Wallet' } else if ( currentBondState?.amount === 0 && @@ -71,7 +74,7 @@ const BondingActions = ({ globalAction }) => { return 'No Withdrawals' } return ActionType[globalAction] - }, [isWalletConnected, currentBondState, globalAction, totalWithdrawable]) + }, [connected, currentBondState, globalAction, totalWithdrawable]) const BondingActionButton = ({ action }) => { const actionString = ActionType[action].toString() @@ -153,7 +156,7 @@ const BondingActions = ({ globalAction }) => { ( - {isLoading && isWalletConnected ? ( + {isLoading && connected ? ( { txStep === TxStep.Posting || txStep === TxStep.Broadcasting || (globalAction === ActionType.bond && currentBondState.amount <= 0 && - isWalletConnected) || + connected) || (currentBondState.amount === 0 && globalAction === ActionType.unbond && - isWalletConnected) || + connected) || (totalWithdrawable === 0 && ActionType.withdraw === globalAction) } maxWidth={580} @@ -255,7 +258,7 @@ const BondingActions = ({ globalAction }) => { txStep === TxStep.Broadcasting } onClick={ () => { - if (isWalletConnected) { + if (connected) { let { denom } = config.bonding_tokens.find((token) => token.symbol === currentBondState.tokenSymbol) if (globalAction === ActionType.withdraw) { denom = getFirstDenomWithPositiveAmount(withdrawableInfos, @@ -265,7 +268,7 @@ const BondingActions = ({ globalAction }) => { globalAction, currentBondState.amount, denom, ) } else { - openView() + openModal() } }} style={{ textTransform: 'capitalize' }} diff --git a/components/Pages/Bonding/BondingActions/Unbond.tsx b/components/Pages/Bonding/BondingActions/Unbond.tsx index 5ea65401..38747fff 100644 --- a/components/Pages/Bonding/BondingActions/Unbond.tsx +++ b/components/Pages/Bonding/BondingActions/Unbond.tsx @@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { Controller, useForm } from 'react-hook-form' import { useMediaQuery, VStack } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useConnect } from '@quirks/react' import AssetInput from 'components/AssetInput/index' import { BondingTokenState, TokenBalance } from 'components/Pages/Bonding/BondingActions/Bond' import { BondedData } from 'components/Pages/Bonding/hooks/getBonded'; @@ -12,8 +12,8 @@ import { bondingState } from 'state/bondingState' import { chainState } from 'state/chainState' const Unbond = ({ bondedAssets }: { bondedAssets: BondedData[] }) => { - const { walletChainName, network, chainId } = useRecoilValue(chainState) - const { isWalletConnected } = useChain(walletChainName) + const { network, chainId } = useRecoilValue(chainState) + const { connected } = useConnect() const [isMobile] = useMediaQuery('(max-width: 720px)') const [currentBondState, setCurrentBondState] = useRecoilState(bondingState) @@ -51,7 +51,7 @@ const Unbond = ({ bondedAssets }: { bondedAssets: BondedData[] }) => { denom: firstToken.denom, }) } - }, [isWalletConnected, config]) + }, [connected, config]) const { control } = useForm({ mode: 'onChange', diff --git a/components/Pages/Bonding/BondingActions/Withdraw.tsx b/components/Pages/Bonding/BondingActions/Withdraw.tsx index f46edd21..334f38ce 100644 --- a/components/Pages/Bonding/BondingActions/Withdraw.tsx +++ b/components/Pages/Bonding/BondingActions/Withdraw.tsx @@ -7,7 +7,7 @@ import { Text, VStack, } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useConnect } from '@quirks/react' import { BondingTokenState } from 'components/Pages/Bonding/BondingActions/Bond' import { UnbondingData } from 'components/Pages/Bonding/hooks/getUnbonding' import { WithdrawableInfo } from 'components/Pages/Bonding/hooks/getWithdrawable' @@ -30,8 +30,8 @@ const Withdraw = ({ withdrawableInfos, unbondingPeriodInNano, }: Props) => { - const { walletChainName, network, chainId } = useRecoilValue(chainState) - const { isWalletConnected } = useChain(walletChainName) + const { network, chainId } = useRecoilValue(chainState) + const { connected } = useConnect() const prices = usePrices() @@ -70,7 +70,7 @@ const Withdraw = ({ denom: firstToken.denom, }) } - }, [isWalletConnected, config]) + }, [connected, config]) const withdrawableTokens = withdrawableInfos?.map((row) => ({ ...row, @@ -103,10 +103,10 @@ const Withdraw = ({ - {isWalletConnected ? `$${dollarValue.toLocaleString()}` : 'n/a'} + {connected ? `$${dollarValue.toLocaleString()}` : 'n/a'} ) @@ -146,7 +146,7 @@ const Withdraw = ({ - {isWalletConnected && + {connected && unbondingRequests && unbondingRequests?.length > 0 && ( { + const { coin } = await import('@cosmjs/stargate'); + const handleMsg = { bond: { asset: { diff --git a/components/Pages/Bonding/BondingActions/hooks/claimRewards.ts b/components/Pages/Bonding/BondingActions/hooks/claimRewards.ts index 8a0c1750..e8ac3365 100644 --- a/components/Pages/Bonding/BondingActions/hooks/claimRewards.ts +++ b/components/Pages/Bonding/BondingActions/hooks/claimRewards.ts @@ -1,8 +1,7 @@ -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate'; +import { type SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import { type InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate'; import { Config } from 'components/Pages/Bonding/hooks/useDashboardData' import { ADV_MEMO, ChainId } from 'constants/index' -import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx' import { createGasFee } from 'services/treasuryService' import { createExecuteMessage } from 'util/messages/createExecuteMessage' @@ -12,6 +11,7 @@ export const claimRewards: any = async ( config: Config, injectiveSigningClient?: InjectiveSigningStargateClient, ) => { + const { TxRaw } = await import('cosmjs-types/cosmos/tx/v1beta1/tx') const handleMsg = { claim: {}, } diff --git a/components/Pages/Bonding/BondingActions/hooks/createNewEpoch.ts b/components/Pages/Bonding/BondingActions/hooks/createNewEpoch.ts index 2a694cdc..cfd55389 100644 --- a/components/Pages/Bonding/BondingActions/hooks/createNewEpoch.ts +++ b/components/Pages/Bonding/BondingActions/hooks/createNewEpoch.ts @@ -1,8 +1,7 @@ -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' +import { type SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import { type InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' import { Config } from 'components/Pages/Bonding/hooks/useDashboardData' import { ADV_MEMO, ChainId } from 'constants/index' -import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx' import { createGasFee } from 'services/treasuryService' import { createExecuteMessage } from 'util/messages/createExecuteMessage' @@ -12,6 +11,8 @@ export const createNewEpoch: any = async ( address: string, injectiveSigningClient?: InjectiveSigningStargateClient, ) => { + const { TxRaw } = await import('cosmjs-types/cosmos/tx/v1beta1/tx') + const handleMsg = { new_epoch: {}, } diff --git a/components/Pages/Bonding/BondingActions/hooks/unbondTokens.ts b/components/Pages/Bonding/BondingActions/hooks/unbondTokens.ts index 1fa52a4f..f593dfce 100644 --- a/components/Pages/Bonding/BondingActions/hooks/unbondTokens.ts +++ b/components/Pages/Bonding/BondingActions/hooks/unbondTokens.ts @@ -1,8 +1,7 @@ -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' +import { type SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import { type InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' import { Config } from 'components/Pages/Bonding/hooks/useDashboardData' import { ADV_MEMO, ChainId } from 'constants/index' -import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; import { createGasFee } from 'services/treasuryService' import { createExecuteMessage } from 'util/messages/createExecuteMessage' @@ -14,6 +13,7 @@ export const unbondTokens: any = async ( config: Config, injectiveSigningClient?: InjectiveSigningStargateClient, ) => { + const { TxRaw } = await import('cosmjs-types/cosmos/tx/v1beta1/tx') const handleMsg = { unbond: { asset: { diff --git a/components/Pages/Bonding/BondingActions/hooks/useTransaction.tsx b/components/Pages/Bonding/BondingActions/hooks/useTransaction.tsx index c841e5cb..505ed1d9 100644 --- a/components/Pages/Bonding/BondingActions/hooks/useTransaction.tsx +++ b/components/Pages/Bonding/BondingActions/hooks/useTransaction.tsx @@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { useMutation, useQuery } from 'react-query' import { useToast } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import Finder from 'components/Finder' import { bondTokens } from 'components/Pages/Bonding/BondingActions/hooks/bondTokens' import { claimRewards } from 'components/Pages/Bonding/BondingActions/hooks/claimRewards' diff --git a/components/Pages/Bonding/BondingActions/hooks/withdrawTokens.ts b/components/Pages/Bonding/BondingActions/hooks/withdrawTokens.ts index acba1338..bb0698c0 100644 --- a/components/Pages/Bonding/BondingActions/hooks/withdrawTokens.ts +++ b/components/Pages/Bonding/BondingActions/hooks/withdrawTokens.ts @@ -1,8 +1,7 @@ -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' +import { type SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import { type InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' import { Config } from 'components/Pages/Bonding/hooks/useDashboardData' import { ADV_MEMO, ChainId } from 'constants/index' -import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; import { createGasFee } from 'services/treasuryService' import { createExecuteMessage } from 'util/messages/createExecuteMessage' @@ -13,6 +12,8 @@ export const withdrawTokens: any = async ( config: Config, injectiveSigningClient?: InjectiveSigningStargateClient, ) => { + const { TxRaw } = await import('cosmjs-types/cosmos/tx/v1beta1/tx') + const handleMsg = { withdraw: { denom, diff --git a/components/Pages/Bonding/RewardsComponent.tsx b/components/Pages/Bonding/RewardsComponent.tsx index 028aafa3..b9e25753 100644 --- a/components/Pages/Bonding/RewardsComponent.tsx +++ b/components/Pages/Bonding/RewardsComponent.tsx @@ -10,7 +10,6 @@ import { VStack, keyframes, } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' import { BondingActionTooltip } from 'components/Pages/Bonding/BondingActions/BondingActionTooltip' import useTransaction from 'components/Pages/Bonding/BondingActions/hooks/useTransaction' import { @@ -20,6 +19,7 @@ import { import { RewardsTooltip } from 'components/Pages/Bonding/RewardsTooltip' import useForceEpochAndTakingSnapshots from 'components/Pages/Trade/Liquidity/hooks/useForceEpochAndTakingSnapshots' import { kBorderRadius, kBg } from 'constants/visualComponentConstants' +import { useWalletModal } from 'hooks/useWalletModal' import { useRecoilValue } from 'recoil' import { chainState } from 'state/chainState' import { TxStep } from 'types/index' @@ -116,9 +116,9 @@ const RewardsComponent = ({ weightInfo, globalInfo, }) => { - const { network, chainId, walletChainName } = useRecoilValue(chainState) + const { network, chainId } = useRecoilValue(chainState) - const { openView } = useChain(walletChainName) + const { openModal } = useWalletModal() const claimableRewards = useMemo(() => totalGlobalClaimable * Number(weightInfo?.share || 0), [totalGlobalClaimable, weightInfo]) @@ -291,7 +291,7 @@ const RewardsComponent = ({ ActionType.claim, null, null, ) } else { - openView() + openModal() } }} style={{ textTransform: 'capitalize' }} diff --git a/components/Pages/Bonding/hooks/getBonded.ts b/components/Pages/Bonding/hooks/getBonded.ts index 0f30886f..3e926352 100644 --- a/components/Pages/Bonding/hooks/getBonded.ts +++ b/components/Pages/Bonding/hooks/getBonded.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' +import { type CosmWasmClient, type JsonObject } from '@cosmjs/cosmwasm-stargate' import { convertMicroDenomToDenom } from 'util/conversion' import { Config } from './useDashboardData' diff --git a/components/Pages/Bonding/hooks/getBondingConfig.ts b/components/Pages/Bonding/hooks/getBondingConfig.ts index e1e62ba5..2eb6d953 100644 --- a/components/Pages/Bonding/hooks/getBondingConfig.ts +++ b/components/Pages/Bonding/hooks/getBondingConfig.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' import { Config } from './useDashboardData' @@ -17,15 +17,6 @@ export interface BondingContractConfig { bonding_assets: BondingAsset[] } -export const getBondingConfig = async (client: CosmWasmClient | null, - config: Config) => { - if (!client && !config) { - return null - } - const bondingConfig = await fetchConfig(client, config) - return { bondingConfig } -} - export const fetchConfig = async (client: CosmWasmClient, config: Config): Promise => { // TODO: API @@ -36,3 +27,12 @@ export const fetchConfig = async (client: CosmWasmClient, return result as BondingContractConfig } + +export const getBondingConfig = async (client: CosmWasmClient | null, + config: Config) => { + if (!client && !config) { + return null + } + const bondingConfig = await fetchConfig(client, config) + return { bondingConfig } +} diff --git a/components/Pages/Bonding/hooks/getClaimable.ts b/components/Pages/Bonding/hooks/getClaimable.ts index d4a32d39..24738500 100644 --- a/components/Pages/Bonding/hooks/getClaimable.ts +++ b/components/Pages/Bonding/hooks/getClaimable.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' import { convertMicroDenomToDenom } from 'util/conversion' import { Config } from './useDashboardData' @@ -36,6 +36,19 @@ interface Data { epochs: Epoch[] } +const fetchClaimableData = async ( + client: CosmWasmClient, + address: string, + config: Config, +): Promise => { + const result: JsonObject = await client.queryContractSmart(config.fee_distributor, + { + claimable: { address }, + }) + + return result as Data +} + export const getClaimable = async ( client: CosmWasmClient, address: string, @@ -57,15 +70,3 @@ export const getClaimable = async ( return { totalGlobalClaimable, lastClaimedTime } } -const fetchClaimableData = async ( - client: CosmWasmClient, - address: string, - config: Config, -): Promise => { - const result: JsonObject = await client.queryContractSmart(config.fee_distributor, - { - claimable: { address }, - }) - - return result as Data -} diff --git a/components/Pages/Bonding/hooks/getClaimableEpochs.ts b/components/Pages/Bonding/hooks/getClaimableEpochs.ts index 89ae2fb2..12948906 100644 --- a/components/Pages/Bonding/hooks/getClaimableEpochs.ts +++ b/components/Pages/Bonding/hooks/getClaimableEpochs.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' import { convertMicroDenomToDenom } from 'util/conversion' import { Config } from './useDashboardData' @@ -36,6 +36,15 @@ interface Data { epochs: Epoch[] } +export const fetchClaimableEpoch = async (client: CosmWasmClient, + config: Config): Promise => { + const result: JsonObject = await client.queryContractSmart(config.fee_distributor, + { + claimable_epochs: {}, + }) + return result as Data +} + export const getClaimableEpochs = async (client: CosmWasmClient, config: Config) => { if (!client) { @@ -75,12 +84,3 @@ export const getClaimableEpochs = async (client: CosmWasmClient, return { globalAvailableRewards, annualRewards } } - -export const fetchClaimableEpoch = async (client: CosmWasmClient, - config: Config): Promise => { - const result: JsonObject = await client.queryContractSmart(config.fee_distributor, - { - claimable_epochs: {}, - }) - return result as Data -} diff --git a/components/Pages/Bonding/hooks/getCurrentEpoch.ts b/components/Pages/Bonding/hooks/getCurrentEpoch.ts index 6e8acceb..79696384 100644 --- a/components/Pages/Bonding/hooks/getCurrentEpoch.ts +++ b/components/Pages/Bonding/hooks/getCurrentEpoch.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' import { Config } from './useDashboardData' diff --git a/components/Pages/Bonding/hooks/getFeeDistributorConfig.ts b/components/Pages/Bonding/hooks/getFeeDistributorConfig.ts index c522476d..69ec990d 100644 --- a/components/Pages/Bonding/hooks/getFeeDistributorConfig.ts +++ b/components/Pages/Bonding/hooks/getFeeDistributorConfig.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' import { Config } from './useDashboardData' diff --git a/components/Pages/Bonding/hooks/getGlobalIndex.ts b/components/Pages/Bonding/hooks/getGlobalIndex.ts index e95b8dd9..30bc838e 100644 --- a/components/Pages/Bonding/hooks/getGlobalIndex.ts +++ b/components/Pages/Bonding/hooks/getGlobalIndex.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' import { Config } from './useDashboardData' diff --git a/components/Pages/Bonding/hooks/getTotalBonded.ts b/components/Pages/Bonding/hooks/getTotalBonded.ts index 3276ef28..a1a7c318 100644 --- a/components/Pages/Bonding/hooks/getTotalBonded.ts +++ b/components/Pages/Bonding/hooks/getTotalBonded.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' import { convertMicroDenomToDenom } from 'util/conversion' import { Config } from './useDashboardData' diff --git a/components/Pages/Bonding/hooks/getUnbonding.ts b/components/Pages/Bonding/hooks/getUnbonding.ts index e32e8fd6..6ccbc90c 100644 --- a/components/Pages/Bonding/hooks/getUnbonding.ts +++ b/components/Pages/Bonding/hooks/getUnbonding.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { fetchConfig } from 'components/Pages/Bonding/hooks/getBondingConfig' import { convertMicroDenomToDenom } from 'util/conversion' import { nanoToMilli } from 'util/conversion/timeUtil' diff --git a/components/Pages/Bonding/hooks/getWeight.ts b/components/Pages/Bonding/hooks/getWeight.ts index b23ecd80..5014cc54 100644 --- a/components/Pages/Bonding/hooks/getWeight.ts +++ b/components/Pages/Bonding/hooks/getWeight.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' import { Config } from './useDashboardData' @@ -10,6 +10,19 @@ export interface WeightInfo { timestamp: string } +const fetchWeight = async ( + client: CosmWasmClient, + address: string, + config: Config, +): Promise => { + const result: JsonObject = await client.queryContractSmart(config.whale_lair, + { + weight: { address }, + }) + + return result as WeightInfo +} + export const getWeight = async ( client: CosmWasmClient, address: string, @@ -28,16 +41,3 @@ export const getWeight = async ( return 0 } } - -const fetchWeight = async ( - client: CosmWasmClient, - address: string, - config: Config, -): Promise => { - const result: JsonObject = await client.queryContractSmart(config.whale_lair, - { - weight: { address }, - }) - - return result as WeightInfo -} diff --git a/components/Pages/Bonding/hooks/getWithdrawable.ts b/components/Pages/Bonding/hooks/getWithdrawable.ts index 66450c0a..640dfc68 100644 --- a/components/Pages/Bonding/hooks/getWithdrawable.ts +++ b/components/Pages/Bonding/hooks/getWithdrawable.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { convertMicroDenomToDenom } from 'util/conversion' import { Config } from './useDashboardData' diff --git a/components/Pages/Dashboard/hooks/getParamsAndCalculateApr.ts b/components/Pages/Dashboard/hooks/getParamsAndCalculateApr.ts index 723c9b30..dc71b6d8 100644 --- a/components/Pages/Dashboard/hooks/getParamsAndCalculateApr.ts +++ b/components/Pages/Dashboard/hooks/getParamsAndCalculateApr.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { getClaimableEpochs } from 'components/Pages/Bonding/hooks/getClaimableEpochs' import { getGlobalIndex } from 'components/Pages/Bonding/hooks/getGlobalIndex' import { Config } from 'components/Pages/Bonding/hooks/useDashboardData' diff --git a/components/Pages/Flashloan/FlashloanForm.tsx b/components/Pages/Flashloan/FlashloanForm.tsx index 4a2769ac..271ce21c 100644 --- a/components/Pages/Flashloan/FlashloanForm.tsx +++ b/components/Pages/Flashloan/FlashloanForm.tsx @@ -10,10 +10,8 @@ import { VStack, Stack, } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useConnect } from '@quirks/react' import { kBg, kBorderRadius } from 'constants/visualComponentConstants' -import { useRecoilValue } from 'recoil' -import { chainState } from 'state/chainState' import { TxStep } from 'types/index' import Editor from './Editor' @@ -44,8 +42,7 @@ const FlashloanForm = () => { const containerRef = useRef(null) const [error, setError] = useState(null) const [json, setJson] = useState(defaultJson) - const { walletChainName } = useRecoilValue(chainState) - const { isWalletConnected } = useChain(walletChainName) + const { connected } = useConnect(); const tx = useFlashloan({ json }) @@ -86,7 +83,7 @@ const FlashloanForm = () => { }, [containerRef, editorRef, options]) const buttonLabel = useMemo(() => { - if (!isWalletConnected) { + if (!connected) { return 'Connect Wallet' } else if (error) { return error @@ -175,7 +172,7 @@ const FlashloanForm = () => { tx?.txStep === TxStep.Posting || tx?.txStep === TxStep.Broadcasting } - disabled={Boolean(error) || !isWalletConnected} + disabled={Boolean(error) || !connected} > {buttonLabel} diff --git a/components/Pages/Flashloan/Vaults/ManagePosition/ManagePosition.tsx b/components/Pages/Flashloan/Vaults/ManagePosition/ManagePosition.tsx index f20851e7..7874b1ba 100644 --- a/components/Pages/Flashloan/Vaults/ManagePosition/ManagePosition.tsx +++ b/components/Pages/Flashloan/Vaults/ManagePosition/ManagePosition.tsx @@ -13,7 +13,7 @@ import { Text, VStack, } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain, useConnect } from '@quirks/react' import useVaults, { useVaultDeposit } from 'components/Pages/Flashloan/Vaults/hooks/useVaults' import DepositForm from 'components/Pages/Flashloan/Vaults/ManagePosition/DepositForm' import WithdrawForm from 'components/Pages/Flashloan/Vaults/ManagePosition/WithdrawForm' @@ -30,7 +30,8 @@ const ManagePosition = () => { const chains: Array = useChainInfos() const params = new URLSearchParams(location.search) const { chainId, walletChainName } = useRecoilValue(chainState) - const { isWalletConnected, address } = useChain(walletChainName) + const { address } = useChain(walletChainName) + const { connected } = useConnect() const vaultId = params.get('vault') || 'JUNO' const vault = useMemo(() => vaults?.vaults.find((v) => v.vault_assets?.symbol === vaultId), @@ -120,7 +121,7 @@ const ManagePosition = () => { {vault?.vault_assets?.symbol && ( { { const [allVaultsInitialized, setAllVaultsInitialized] = useState(false) - const { walletChainName } = useRecoilValue(chainState) - const { isWalletConnected } = useChain(walletChainName) + const { connected } = useConnect() const { vaults, isLoading } = useVaults() const router = useRouter() const chainIdParam = router.query.chainId as string const allVaults = useMemo(() => { - if (!vaults && isWalletConnected) { + if (!vaults && connected) { return [] } setAllVaultsInitialized(true) diff --git a/components/Pages/Flashloan/Vaults/hooks/createDepositMsgs.ts b/components/Pages/Flashloan/Vaults/hooks/createDepositMsgs.ts index 7cc51861..90d11310 100644 --- a/components/Pages/Flashloan/Vaults/hooks/createDepositMsgs.ts +++ b/components/Pages/Flashloan/Vaults/hooks/createDepositMsgs.ts @@ -1,4 +1,4 @@ -import { MsgExecuteContractEncodeObject } from '@cosmjs/cosmwasm-stargate' +import type { MsgExecuteContractEncodeObject } from '@cosmjs/cosmwasm-stargate' import { coin } from '@cosmjs/proto-signing' import { createExecuteMessage, createIncreaseAllowanceMessage } from 'util/messages/index' diff --git a/components/Pages/Flashloan/Vaults/hooks/createWithdrawMsgs.ts b/components/Pages/Flashloan/Vaults/hooks/createWithdrawMsgs.ts index 66382e21..6207f1df 100644 --- a/components/Pages/Flashloan/Vaults/hooks/createWithdrawMsgs.ts +++ b/components/Pages/Flashloan/Vaults/hooks/createWithdrawMsgs.ts @@ -1,4 +1,4 @@ -import { MsgExecuteContractEncodeObject } from '@cosmjs/cosmwasm-stargate' +import type { MsgExecuteContractEncodeObject } from '@cosmjs/cosmwasm-stargate' import { coin } from '@cosmjs/stargate' import { isNativeToken } from 'services/asset' import { toBase64 } from 'util/conversion/index' diff --git a/components/Pages/Flashloan/Vaults/hooks/executeVault.ts b/components/Pages/Flashloan/Vaults/hooks/executeVault.ts index 18490b3b..57ecdba9 100644 --- a/components/Pages/Flashloan/Vaults/hooks/executeVault.ts +++ b/components/Pages/Flashloan/Vaults/hooks/executeVault.ts @@ -1,7 +1,6 @@ -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' +import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import type { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' import { ADV_MEMO, ChainId } from 'constants/index' -import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx' import { createGasFee } from 'services/treasuryService' type ExecuteAddLiquidityArgs = { @@ -17,6 +16,7 @@ export const executeVault = async ({ injectiveSigningClient, senderAddress, }: ExecuteAddLiquidityArgs): Promise => { + const { TxRaw } = await import('cosmjs-types/cosmos/tx/v1beta1/tx') if (injectiveSigningClient && await signingClient.getChainId() === ChainId.injective) { const injectiveTxData = await injectiveSigningClient.sign( senderAddress, executionMsgs, await createGasFee( diff --git a/components/Pages/Flashloan/Vaults/hooks/useDeposit.tsx b/components/Pages/Flashloan/Vaults/hooks/useDeposit.tsx index 86494411..494f2bba 100644 --- a/components/Pages/Flashloan/Vaults/hooks/useDeposit.tsx +++ b/components/Pages/Flashloan/Vaults/hooks/useDeposit.tsx @@ -1,6 +1,6 @@ import { useMemo } from 'react' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import { createDepositExecuteMsgs } from 'components/Pages/Flashloan/Vaults/hooks/createDepositMsgs' import useTransaction from 'components/Pages/Flashloan/Vaults/hooks/useTransaction' import { useClients } from 'hooks/useClients' diff --git a/components/Pages/Flashloan/Vaults/hooks/useTransaction.tsx b/components/Pages/Flashloan/Vaults/hooks/useTransaction.tsx index c6abd130..b2a97a1b 100644 --- a/components/Pages/Flashloan/Vaults/hooks/useTransaction.tsx +++ b/components/Pages/Flashloan/Vaults/hooks/useTransaction.tsx @@ -2,8 +2,8 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { useMutation, useQuery, useQueryClient } from 'react-query' import { useToast } from '@chakra-ui/react' -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' +import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import type { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' import Finder from 'components/Finder' import { executeVault } from 'components/Pages/Flashloan/Vaults/hooks/executeVault' import { ChainId } from 'constants/index' diff --git a/components/Pages/Flashloan/Vaults/hooks/useVaults.tsx b/components/Pages/Flashloan/Vaults/hooks/useVaults.tsx index f7c8bc99..c7091d39 100644 --- a/components/Pages/Flashloan/Vaults/hooks/useVaults.tsx +++ b/components/Pages/Flashloan/Vaults/hooks/useVaults.tsx @@ -1,8 +1,8 @@ import { useMemo } from 'react' import { useQuery } from 'react-query' -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { useChain } from '@cosmos-kit/react-lite' +import type { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import { useChain } from '@quirks/react' import { useClients } from 'hooks/useClients' import { usePrices } from 'hooks/usePrices' import { formatPrice } from 'libs/num' diff --git a/components/Pages/Flashloan/Vaults/hooks/useWithdraw.tsx b/components/Pages/Flashloan/Vaults/hooks/useWithdraw.tsx index b8d2d51a..1ccfb378 100644 --- a/components/Pages/Flashloan/Vaults/hooks/useWithdraw.tsx +++ b/components/Pages/Flashloan/Vaults/hooks/useWithdraw.tsx @@ -1,6 +1,6 @@ import { useMemo } from 'react' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import { createWithdrawExecuteMsgs, } from 'components/Pages/Flashloan/Vaults/hooks/createWithdrawMsgs' diff --git a/components/Pages/Flashloan/hooks/executeFlashloan.ts b/components/Pages/Flashloan/hooks/executeFlashloan.ts index dcdd13ec..81c822ab 100644 --- a/components/Pages/Flashloan/hooks/executeFlashloan.ts +++ b/components/Pages/Flashloan/hooks/executeFlashloan.ts @@ -1,7 +1,6 @@ -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' +import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import type { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' import { ADV_MEMO, ChainId } from 'constants/index'; -import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx' import { createGasFee } from 'services/treasuryService'; import { createExecuteMessage } from 'util/messages' @@ -20,6 +19,7 @@ export const executeFlashloan = async ({ senderAddress, injectiveSigningClient, }: ExecuteFlashloanArgs): Promise => { + const { TxRaw } = await import('cosmjs-types/cosmos/tx/v1beta1/tx') const execMsg = createExecuteMessage({ senderAddress, contractAddress, diff --git a/components/Pages/Flashloan/hooks/useFlashloan.ts b/components/Pages/Flashloan/hooks/useFlashloan.ts index 1dcff14e..67b5c67b 100644 --- a/components/Pages/Flashloan/hooks/useFlashloan.ts +++ b/components/Pages/Flashloan/hooks/useFlashloan.ts @@ -1,6 +1,6 @@ import { useMemo } from 'react' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import flashLoanContract from 'constants/vaultRouterAddresses.json' import { useClients } from 'hooks/useClients' import { useRecoilValue } from 'recoil' diff --git a/components/Pages/Flashloan/hooks/useTransaction.tsx b/components/Pages/Flashloan/hooks/useTransaction.tsx index 03f009db..ebe75eef 100644 --- a/components/Pages/Flashloan/hooks/useTransaction.tsx +++ b/components/Pages/Flashloan/hooks/useTransaction.tsx @@ -2,8 +2,8 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { useMutation, useQuery, useQueryClient } from 'react-query' import { useToast } from '@chakra-ui/react' -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate'; +import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import type { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate'; import Finder from 'components/Finder' import { ChainId } from 'constants/index' import useDebounceValue from 'hooks/useDebounceValue' diff --git a/components/Pages/Trade/Incentivize/Create.tsx b/components/Pages/Trade/Incentivize/Create.tsx index 839a0ff6..4883ff6a 100644 --- a/components/Pages/Trade/Incentivize/Create.tsx +++ b/components/Pages/Trade/Incentivize/Create.tsx @@ -9,14 +9,13 @@ import { Stack, useMediaQuery, } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useConnect } from '@quirks/react' import Input from 'components/AssetInput/Input' import { useOpenFlow } from 'components/Pages/Trade/Incentivize/hooks/useOpenFlow' import SubmitButton from 'components/SubmitButton' import { TooltipWithChildren } from 'components/TooltipWithChildren' import { WHALE_TOKEN_SYMBOL } from 'constants/index' import { useRecoilValue } from 'recoil' -import { chainState } from 'state/chainState' import { txRecoilState } from 'state/txRecoilState' import { TxStep } from 'types/common' @@ -47,8 +46,7 @@ const Create = ({ poolId }: Props) => { }) const formData = watch() - const { walletChainName } = useRecoilValue(chainState) - const { isWalletConnected } = useChain(walletChainName) + const { connected } = useConnect(); const { txStep } = useRecoilValue(txRecoilState) const [isMobile] = useMediaQuery('(max-width: 640px)') const { simulate, submit } = useOpenFlow({ poolId, @@ -138,7 +136,7 @@ const Create = ({ poolId }: Props) => { txStep === TxStep.Posting || txStep === TxStep.Broadcasting } - isDisabled={!isValid || txStep !== TxStep.Ready || !isWalletConnected} + isDisabled={!isValid || txStep !== TxStep.Ready || !connected} /> ) diff --git a/components/Pages/Trade/Incentivize/hooks/useClosePosition.ts b/components/Pages/Trade/Incentivize/hooks/useClosePosition.ts index 6db6523d..c2e85331 100644 --- a/components/Pages/Trade/Incentivize/hooks/useClosePosition.ts +++ b/components/Pages/Trade/Incentivize/hooks/useClosePosition.ts @@ -1,7 +1,7 @@ import { useMemo } from 'react' import { useMutation } from 'react-query' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import { usePoolFromListQueryById } from 'components/Pages/Trade/Pools/hooks/usePoolsListQuery' import { ADV_MEMO, ChainId } from 'constants/index' import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; diff --git a/components/Pages/Trade/Incentivize/hooks/useCurrentEpoch.ts b/components/Pages/Trade/Incentivize/hooks/useCurrentEpoch.ts index 147666a1..9e9434f8 100644 --- a/components/Pages/Trade/Incentivize/hooks/useCurrentEpoch.ts +++ b/components/Pages/Trade/Incentivize/hooks/useCurrentEpoch.ts @@ -1,6 +1,6 @@ import { useQuery } from 'react-query' -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { fetchCurrentEpoch } from 'components/Pages/Bonding/hooks/getCurrentEpoch' import { Config } from 'components/Pages/Bonding/hooks/useDashboardData' diff --git a/components/Pages/Trade/Incentivize/hooks/useIncentivePoolInfo.ts b/components/Pages/Trade/Incentivize/hooks/useIncentivePoolInfo.ts index 7090663b..f25b7a0f 100644 --- a/components/Pages/Trade/Incentivize/hooks/useIncentivePoolInfo.ts +++ b/components/Pages/Trade/Incentivize/hooks/useIncentivePoolInfo.ts @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react' import { useQuery } from 'react-query' -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { Config, useConfig, diff --git a/components/Pages/Trade/Incentivize/hooks/useOpenFlow.ts b/components/Pages/Trade/Incentivize/hooks/useOpenFlow.ts index b6dee351..5732f6bb 100644 --- a/components/Pages/Trade/Incentivize/hooks/useOpenFlow.ts +++ b/components/Pages/Trade/Incentivize/hooks/useOpenFlow.ts @@ -1,9 +1,8 @@ import { useMemo } from 'react' import { useMutation } from 'react-query' -import { MsgExecuteContractEncodeObject } from '@cosmjs/cosmwasm-stargate' +import type { MsgExecuteContractEncodeObject } from '@cosmjs/cosmwasm-stargate' import { coin } from '@cosmjs/proto-signing' -import { useChain } from '@cosmos-kit/react-lite' import { Config, useConfig, @@ -27,6 +26,7 @@ import { createExecuteMessage, createIncreaseAllowanceMessage, } from 'util/messages/index' +import { useChain } from '@quirks/react' interface Props { poolId: string diff --git a/components/Pages/Trade/Incentivize/hooks/usePoolUserShare.ts b/components/Pages/Trade/Incentivize/hooks/usePoolUserShare.ts index 3e0db6bc..49d546d7 100644 --- a/components/Pages/Trade/Incentivize/hooks/usePoolUserShare.ts +++ b/components/Pages/Trade/Incentivize/hooks/usePoolUserShare.ts @@ -1,6 +1,6 @@ import { useQuery } from 'react-query' -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' export interface AddressInfo { address: string diff --git a/components/Pages/Trade/Incentivize/hooks/useQueryIncentiveContracts.ts b/components/Pages/Trade/Incentivize/hooks/useQueryIncentiveContracts.ts index cbfb008b..4ec520f8 100644 --- a/components/Pages/Trade/Incentivize/hooks/useQueryIncentiveContracts.ts +++ b/components/Pages/Trade/Incentivize/hooks/useQueryIncentiveContracts.ts @@ -1,6 +1,6 @@ import { useQuery } from 'react-query' -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { Config, useConfig, diff --git a/components/Pages/Trade/Liquidity/Claim.tsx b/components/Pages/Trade/Liquidity/Claim.tsx index d483f484..f88eb765 100644 --- a/components/Pages/Trade/Liquidity/Claim.tsx +++ b/components/Pages/Trade/Liquidity/Claim.tsx @@ -1,7 +1,7 @@ import { useMemo } from 'react' import { HStack, VStack } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useConnect } from '@quirks/react' import { useConfig } from 'components/Pages/Bonding/hooks/useDashboardData' import ClaimTable from 'components/Pages/Trade/Liquidity/ClaimTable' import { useCheckIncentiveSnapshots } from 'components/Pages/Trade/Liquidity/hooks/useCheckIncentiveSnapshots' @@ -11,6 +11,7 @@ import useRewards from 'components/Pages/Trade/Liquidity/hooks/useRewards' import SubmitButton from 'components/SubmitButton' import { TooltipWithChildren } from 'components/TooltipWithChildren' import { useClients } from 'hooks/useClients' +import { useWalletModal } from 'hooks/useWalletModal' import { useRecoilValue } from 'recoil' import { chainState } from 'state/chainState' import { TxStep } from 'types/common' @@ -47,7 +48,8 @@ const Claim = ({ poolId }: Props) => { const claim = useClaim({ poolId }) const { network, chainId, walletChainName } = useRecoilValue(chainState) - const { isWalletConnected, openView } = useChain(walletChainName) + const { connected } = useConnect() + const { openModal } = useWalletModal() const { cosmWasmClient } = useClients(walletChainName) const config = useConfig(network, chainId) @@ -68,7 +70,7 @@ const Claim = ({ poolId }: Props) => { return rewardsSum > 0 }, [rewards]) const buttonLabel = useMemo(() => { - if (!isWalletConnected) { + if (!connected) { return 'Connect Wallet' } else if (Number(totalValue) === 0) { return 'No Rewards' @@ -76,7 +78,7 @@ const Claim = ({ poolId }: Props) => { return 'Take Snapshots' } return 'Claim' - }, [isWalletConnected, totalValue, allSnapshotsTaken]) + }, [connected, totalValue, allSnapshotsTaken]) return ( @@ -86,13 +88,13 @@ const Claim = ({ poolId }: Props) => { label={buttonLabel} isConnected={true} txStep={TxStep.Ready} - isDisabled={(!isClaimable && allSnapshotsTaken) && isWalletConnected} + isDisabled={(!isClaimable && allSnapshotsTaken) && connected} isLoading={ [TxStep.Estimating, TxStep.Posting, TxStep.Broadcasting].includes(claim.txStep)} onClick={() => { - if (isWalletConnected && allSnapshotsTaken && rewards.length !== 0) { + if (connected && allSnapshotsTaken && rewards.length !== 0) { claim.submit() - } else if (!isWalletConnected) { - openView() + } else if (!connected) { + openModal() } else { forceSnapshots.submit() } diff --git a/components/Pages/Trade/Liquidity/ManageLiquidity.tsx b/components/Pages/Trade/Liquidity/ManageLiquidity.tsx index 96705a0b..9baa0017 100644 --- a/components/Pages/Trade/Liquidity/ManageLiquidity.tsx +++ b/components/Pages/Trade/Liquidity/ManageLiquidity.tsx @@ -14,7 +14,7 @@ import { VStack, useMediaQuery, } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain, useConnect } from '@quirks/react' import { useIncentivePoolInfo } from 'components/Pages/Trade/Incentivize/hooks/useIncentivePoolInfo' import { usePoolUserShare } from 'components/Pages/Trade/Incentivize/hooks/usePoolUserShare' import { IncentivePositionsOverview } from 'components/Pages/Trade/Incentivize/IncentivePositionsOverview'; @@ -34,6 +34,7 @@ import { useClients } from 'hooks/useClients' import { usePrices } from 'hooks/usePrices' import { useQueriesDataSelector } from 'hooks/useQueriesDataSelector' import { useTokenList } from 'hooks/useTokenList' +import { useWalletModal } from 'hooks/useWalletModal' import { useRouter } from 'next/router' import { useRecoilState, useRecoilValue } from 'recoil' import { chainState } from 'state/chainState' @@ -48,7 +49,9 @@ const ManageLiquidity = ({ poolIdFromUrl }) => { const chains: Array = useChainInfos() const [tokenList] = useTokenList() const { chainId, walletChainName } = useRecoilValue(chainState) - const { isWalletConnected, address, openView } = useChain(walletChainName) + const { address } = useChain(walletChainName) + const { connected } = useConnect() + const { openModal } = useWalletModal() const [reverse, setReverse] = useState(false) const [isTokenSet, setIsToken] = useState(false) const { data: poolData } = usePoolsListQuery() @@ -262,7 +265,7 @@ const ManageLiquidity = ({ poolIdFromUrl }) => { bondingDays={bondingDays} setReverse={setReverse} reverse={reverse} - isWalletConnected={isWalletConnected} + isWalletConnected={connected} tokenA={tokenA} tokenB={tokenB} onInputChange={onInputChange} @@ -272,17 +275,17 @@ const ManageLiquidity = ({ poolIdFromUrl }) => { chainId={chainId} poolId={poolIdFromUrl} mobile={isMobile} - openView={openView} + openView={openModal} /> )} diff --git a/components/Pages/Trade/Liquidity/Rewards.tsx b/components/Pages/Trade/Liquidity/Rewards.tsx index 653a1c97..a70a9846 100644 --- a/components/Pages/Trade/Liquidity/Rewards.tsx +++ b/components/Pages/Trade/Liquidity/Rewards.tsx @@ -1,19 +1,17 @@ import { useMemo } from 'react' import { Divider, HStack, Text, VStack } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useConnect } from '@quirks/react' import { AvailableRewards } from 'components/Pages/Trade/Liquidity/AvailableRewards' import { RewardToolTip } from 'components/RewardToolTip' -import { useRecoilValue } from 'recoil' -import { chainState } from 'state/chainState' export const Rewards = ({ rewards = [], totalValue, dailyEmissions = [] }) => { const totalUsdValue = useMemo(() => dailyEmissions.reduce((total, item) => total + (isNaN(item.dailyUsdEmission) ? 0 : item.dailyUsdEmission), 0), [dailyEmissions]) - const { walletChainName } = useRecoilValue(chainState) - const { isWalletConnected } = useChain(walletChainName) + const { connected } = useConnect() + return ( { 0} - isWalletConnected={isWalletConnected} + isWalletConnected={connected} > @@ -45,7 +43,7 @@ export const Rewards = ({ rewards = [], totalValue, dailyEmissions = [] }) => { 0} - isWalletConnected={isWalletConnected} + isWalletConnected={connected} > diff --git a/components/Pages/Trade/Liquidity/hooks/createLPMsg.ts b/components/Pages/Trade/Liquidity/hooks/createLPMsg.ts index 75cabae1..de9cc338 100644 --- a/components/Pages/Trade/Liquidity/hooks/createLPMsg.ts +++ b/components/Pages/Trade/Liquidity/hooks/createLPMsg.ts @@ -1,4 +1,4 @@ -import { MsgExecuteContractEncodeObject } from '@cosmjs/cosmwasm-stargate' +import type { MsgExecuteContractEncodeObject } from '@cosmjs/cosmwasm-stargate' import { coin } from '@cosmjs/proto-signing' import { createAsset } from 'services/asset' import { createExecuteMessage, createIncreaseAllowanceMessage } from 'util/messages/index' diff --git a/components/Pages/Trade/Liquidity/hooks/createWithdrawMsgs.ts b/components/Pages/Trade/Liquidity/hooks/createWithdrawMsgs.ts index e8c52259..73ae593d 100644 --- a/components/Pages/Trade/Liquidity/hooks/createWithdrawMsgs.ts +++ b/components/Pages/Trade/Liquidity/hooks/createWithdrawMsgs.ts @@ -1,4 +1,4 @@ -import { MsgExecuteContractEncodeObject } from '@cosmjs/cosmwasm-stargate' +import type { MsgExecuteContractEncodeObject } from '@cosmjs/cosmwasm-stargate' import { coin } from '@cosmjs/stargate' import { toBase64 } from 'util/conversion/index' import { createExecuteMessage, createIncreaseAllowanceMessage } from 'util/messages/index' diff --git a/components/Pages/Trade/Liquidity/hooks/useCheckIncentiveSnapshots.ts b/components/Pages/Trade/Liquidity/hooks/useCheckIncentiveSnapshots.ts index ff0ec5d1..20bc389b 100644 --- a/components/Pages/Trade/Liquidity/hooks/useCheckIncentiveSnapshots.ts +++ b/components/Pages/Trade/Liquidity/hooks/useCheckIncentiveSnapshots.ts @@ -1,6 +1,6 @@ import { useQuery } from 'react-query' -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { Config } from 'components/Pages/Bonding/hooks/useDashboardData' import { useCurrentEpoch } from 'components/Pages/Trade/Incentivize/hooks/useCurrentEpoch' import { useQueryIncentiveContracts } from 'components/Pages/Trade/Incentivize/hooks/useQueryIncentiveContracts' diff --git a/components/Pages/Trade/Liquidity/hooks/useClaim.ts b/components/Pages/Trade/Liquidity/hooks/useClaim.ts index 1e104453..eff1aea9 100644 --- a/components/Pages/Trade/Liquidity/hooks/useClaim.ts +++ b/components/Pages/Trade/Liquidity/hooks/useClaim.ts @@ -1,7 +1,7 @@ import { useMemo } from 'react' import { useMutation } from 'react-query' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import { usePoolFromListQueryById } from 'components/Pages/Trade/Pools/hooks/usePoolsListQuery' import { ADV_MEMO, ChainId } from 'constants/index' import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; diff --git a/components/Pages/Trade/Liquidity/hooks/useClosePosition.ts b/components/Pages/Trade/Liquidity/hooks/useClosePosition.ts index b993db94..fbbd446c 100644 --- a/components/Pages/Trade/Liquidity/hooks/useClosePosition.ts +++ b/components/Pages/Trade/Liquidity/hooks/useClosePosition.ts @@ -1,7 +1,7 @@ import { useMemo } from 'react' import { useMutation } from 'react-query' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import { usePoolFromListQueryById } from 'components/Pages/Trade/Pools/hooks/usePoolsListQuery' import { ADV_MEMO, ChainId } from 'constants/index' import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; diff --git a/components/Pages/Trade/Liquidity/hooks/useDepositTransaction.tsx b/components/Pages/Trade/Liquidity/hooks/useDepositTransaction.tsx index 0dfab86b..94370634 100644 --- a/components/Pages/Trade/Liquidity/hooks/useDepositTransaction.tsx +++ b/components/Pages/Trade/Liquidity/hooks/useDepositTransaction.tsx @@ -2,8 +2,8 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { useMutation, useQuery, useQueryClient } from 'react-query' import { useToast } from '@chakra-ui/react' -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate'; +import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import type { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate'; import Finder from 'components/Finder' import { ChainId } from 'constants/index' import useDebounceValue from 'hooks/useDebounceValue' diff --git a/components/Pages/Trade/Liquidity/hooks/useForceEpochAndTakingSnapshots.ts b/components/Pages/Trade/Liquidity/hooks/useForceEpochAndTakingSnapshots.ts index 1bc10695..1aa00c37 100644 --- a/components/Pages/Trade/Liquidity/hooks/useForceEpochAndTakingSnapshots.ts +++ b/components/Pages/Trade/Liquidity/hooks/useForceEpochAndTakingSnapshots.ts @@ -1,7 +1,7 @@ import { useMemo } from 'react' import { useMutation } from 'react-query' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import { Config } from 'components/Pages/Bonding/hooks/useDashboardData' import { useQueryIncentiveContracts } from 'components/Pages/Trade/Incentivize/hooks/useQueryIncentiveContracts' import { ADV_MEMO, ChainId } from 'constants/index' diff --git a/components/Pages/Trade/Liquidity/hooks/useLockedPositions.ts b/components/Pages/Trade/Liquidity/hooks/useLockedPositions.ts index d7407f59..79409caf 100644 --- a/components/Pages/Trade/Liquidity/hooks/useLockedPositions.ts +++ b/components/Pages/Trade/Liquidity/hooks/useLockedPositions.ts @@ -1,7 +1,7 @@ import { useQuery } from 'react-query' -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'; -import { useChain } from '@cosmos-kit/react-lite' +import type { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'; +import { useChain } from '@quirks/react' import { TokenInfo } from 'components/Pages/Trade/Pools/hooks/usePoolsListQuery' import { useQueryPoolLiquidity } from 'components/Pages/Trade/Pools/hooks/useQueryPoolsLiquidity' import { PositionState } from 'constants/state' @@ -47,7 +47,7 @@ export const fetchPositions = async ( totalAssets: any, totalLpSupply: any, ) => { - // address can be undefined + // Address can be undefined if (!address) { return { data: [] } } diff --git a/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts b/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts index 8367905c..0314786a 100644 --- a/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts +++ b/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts @@ -1,6 +1,6 @@ import { useMemo } from 'react' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import { Config, useConfig, diff --git a/components/Pages/Trade/Liquidity/hooks/useRewards.ts b/components/Pages/Trade/Liquidity/hooks/useRewards.ts index 74c37f8d..76e1718c 100644 --- a/components/Pages/Trade/Liquidity/hooks/useRewards.ts +++ b/components/Pages/Trade/Liquidity/hooks/useRewards.ts @@ -1,7 +1,7 @@ import { useMemo } from 'react' import { useQuery } from 'react-query' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import { TokenInfo } from 'components/Pages/Trade/Pools/hooks/usePoolsListQuery' import { useQueryPoolLiquidity } from 'components/Pages/Trade/Pools/hooks/useQueryPoolsLiquidity' import { useClients } from 'hooks/useClients' diff --git a/components/Pages/Trade/Liquidity/hooks/useWithdraw.ts b/components/Pages/Trade/Liquidity/hooks/useWithdraw.ts index b58b6192..ab53d927 100644 --- a/components/Pages/Trade/Liquidity/hooks/useWithdraw.ts +++ b/components/Pages/Trade/Liquidity/hooks/useWithdraw.ts @@ -1,6 +1,6 @@ import { useMemo } from 'react' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import { createWithdrawExecuteMsgs, createWithdrawMsg, diff --git a/components/Pages/Trade/Liquidity/hooks/useWithdrawPosition.ts b/components/Pages/Trade/Liquidity/hooks/useWithdrawPosition.ts index b5486c18..2cc52129 100644 --- a/components/Pages/Trade/Liquidity/hooks/useWithdrawPosition.ts +++ b/components/Pages/Trade/Liquidity/hooks/useWithdrawPosition.ts @@ -1,7 +1,7 @@ import { useMemo } from 'react' import { useMutation } from 'react-query' -import { useChain } from '@cosmos-kit/react-lite'; +import { useChain } from '@quirks/react'; import { usePoolFromListQueryById } from 'components/Pages/Trade/Pools/hooks/usePoolsListQuery' import { ADV_MEMO, ChainId } from 'constants/index' import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; diff --git a/components/Pages/Trade/Liquidity/hooks/useWithdrawTransaction.tsx b/components/Pages/Trade/Liquidity/hooks/useWithdrawTransaction.tsx index 26302976..390e24cd 100644 --- a/components/Pages/Trade/Liquidity/hooks/useWithdrawTransaction.tsx +++ b/components/Pages/Trade/Liquidity/hooks/useWithdrawTransaction.tsx @@ -2,11 +2,10 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { useMutation, useQuery, useQueryClient } from 'react-query' import { useToast } from '@chakra-ui/react' -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' +import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import type { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' import Finder from 'components/Finder' import { ADV_MEMO, ChainId } from 'constants/index' -import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; import useDebounceValue from 'hooks/useDebounceValue' import { createGasFee } from 'services/treasuryService' import { TxStep } from 'types/common' @@ -109,6 +108,7 @@ export const useWithdrawTransaction: any = ({ ) const { mutate } = useMutation(async () => { + const { TxRaw } = await import('cosmjs-types/cosmos/tx/v1beta1/tx') if (injectiveSigningClient && await signingClient.getChainId() === ChainId.injective) { const injectiveTxData = await injectiveSigningClient.sign( senderAddress, debouncedMsgs, await createGasFee( diff --git a/components/Pages/Trade/Pools/Pools.tsx b/components/Pages/Trade/Pools/Pools.tsx index faf3a70e..9d246610 100644 --- a/components/Pages/Trade/Pools/Pools.tsx +++ b/components/Pages/Trade/Pools/Pools.tsx @@ -10,7 +10,7 @@ import { Tooltip, VStack, } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useConnect } from '@quirks/react' import { useIncentivePoolInfo } from 'components/Pages/Trade/Incentivize/hooks/useIncentivePoolInfo' import { ActionCTAs } from 'components/Pages/Trade/Pools/ActionCTAs' import AllPoolsTable from 'components/Pages/Trade/Pools/AllPoolsTable' @@ -46,7 +46,7 @@ const Pools = () => { const [externalStatsLoading, setExternalStatsLoading] = useState(true) const { chainId, walletChainName } = useRecoilValue(chainState) - const { isWalletConnected } = useChain(walletChainName) + const { connected } = useConnect() const [currentAprHelperState, setAprHelperState] = useRecoilState(aprHelperState) const [showAllPools, setShowAllPools] = useState(false) const { cosmWasmClient } = useClients(walletChainName) @@ -216,13 +216,13 @@ const Pools = () => { const [myPools, setMyPools] = useState([]) useEffect(() => { - if (!isWalletConnected) { + if (!connected) { setMyPools([]) } - }, [isWalletConnected]) + }, [connected]) useEffect(() => { - if (pools && allPools && isWalletConnected) { + if (pools && allPools && connected) { const myLiquidityPools = pools.filter(({ liquidity }) => liquidity?.providedTotal?.tokenAmount > 0) const updatedPools = allPools.filter((pool) => myLiquidityPools.map((myPool) => myPool.pool_id).includes(pool.poolId)).map((pool) => { const myPool = myLiquidityPools.find((myPool) => myPool.pool_id === pool.poolId) @@ -233,7 +233,7 @@ const Pools = () => { }) setMyPools(updatedPools) } - }, [allPools, isWalletConnected]) + }, [allPools, connected]) // Get a list of all myPools pools const myPoolsId = useMemo(() => myPools?.map(({ pool }) => pool), [myPools]) diff --git a/components/Pages/Trade/Pools/hooks/queryPoolInfo.ts b/components/Pages/Trade/Pools/hooks/queryPoolInfo.ts index 12409aec..abef124c 100644 --- a/components/Pages/Trade/Pools/hooks/queryPoolInfo.ts +++ b/components/Pages/Trade/Pools/hooks/queryPoolInfo.ts @@ -1,4 +1,4 @@ -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import type { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { getPoolFromAPI } from 'services/useAPI' export type PoolInfoResponse = { diff --git a/components/Pages/Trade/Pools/hooks/useQueryPoolsLiquidity.ts b/components/Pages/Trade/Pools/hooks/useQueryPoolsLiquidity.ts index 44f67bdf..28154bc8 100644 --- a/components/Pages/Trade/Pools/hooks/useQueryPoolsLiquidity.ts +++ b/components/Pages/Trade/Pools/hooks/useQueryPoolsLiquidity.ts @@ -1,8 +1,8 @@ import { useMemo } from 'react' import { useQueries } from 'react-query' -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { useChain } from '@cosmos-kit/react-lite' +import type { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import { useChain } from '@quirks/react' import useEpoch from 'components/Pages/Trade/Incentivize/hooks/useEpoch' import { fetchFlows } from 'components/Pages/Trade/Incentivize/hooks/useIncentivePoolInfo' import { queryPoolInfo } from 'components/Pages/Trade/Pools/hooks/queryPoolInfo' diff --git a/components/Pages/Trade/Swap/Swap.tsx b/components/Pages/Trade/Swap/Swap.tsx index a1e937b1..49e0e283 100644 --- a/components/Pages/Trade/Swap/Swap.tsx +++ b/components/Pages/Trade/Swap/Swap.tsx @@ -1,7 +1,7 @@ import { FC, useEffect, useMemo, useState } from 'react' import { HStack, Text, VStack } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain, useConnect } from '@quirks/react' import defaultTokens from 'components/Pages/Trade/Swap/defaultTokens.json' import useSwap from 'components/Pages/Trade/Swap/hooks/useSwap' import { tokenSwapAtom } from 'components/Pages/Trade/Swap/swapAtoms' @@ -29,7 +29,8 @@ const Swap: FC = (params) => { const [resetForm, setResetForm] = useState(false) const { chainId, network, walletChainName } = useRecoilValue(chainState) - const { isWalletConnected, address } = useChain(walletChainName) + const { address } = useChain(walletChainName) + const { connected } = useConnect() const chains: Array = useChainInfos() const { tx, simulated, state, path, minReceive, priceImpact } = useSwap({ reverse }) const currentChain = chains.find((row) => row.chainId === chainId) @@ -154,7 +155,7 @@ const Swap: FC = (params) => { { + const { TxRaw } = await import('cosmjs-types/cosmos/tx/v1beta1/tx') if (!tokenA.native) { const increaseAllowanceMessage = createIncreaseAllowanceMessage({ senderAddress, diff --git a/components/Pages/Trade/Swap/hooks/useSwap.ts b/components/Pages/Trade/Swap/hooks/useSwap.ts index d05072f8..f4a8b8cb 100644 --- a/components/Pages/Trade/Swap/hooks/useSwap.ts +++ b/components/Pages/Trade/Swap/hooks/useSwap.ts @@ -1,7 +1,7 @@ import { useMemo } from 'react' import { fromBase64, fromUtf8, toBase64, toUtf8 } from '@cosmjs/encoding' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import { usePoolsListQuery } from 'components/Pages/Trade/Pools/hooks/usePoolsListQuery' import useRoute, { executeMessage } from 'components/Pages/Trade/Swap/hooks/useRoute' import useSimulate from 'components/Pages/Trade/Swap/hooks/useSimulate' diff --git a/components/Pages/Trade/Swap/hooks/useTokenSwap.tsx b/components/Pages/Trade/Swap/hooks/useTokenSwap.tsx index 88a5fbc5..91ce24b8 100644 --- a/components/Pages/Trade/Swap/hooks/useTokenSwap.tsx +++ b/components/Pages/Trade/Swap/hooks/useTokenSwap.tsx @@ -2,7 +2,7 @@ import { toast } from 'react-hot-toast' import { useMutation } from 'react-query' import { Button } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain, useConnect } from '@quirks/react' import { useQueryMatchingPoolForSwap } from 'components/Pages/Trade/Pools/hooks/useQueryMatchingPoolForSwap' import { slippageAtom, tokenSwapAtom } from 'components/Pages/Trade/Swap/swapAtoms' import { useClients } from 'hooks/useClients' @@ -40,7 +40,8 @@ export const useTokenSwap = ({ tokenToTokenPrice, }: UseTokenSwapArgs) => { const { walletChainName } = useRecoilValue(chainState) - const { isWalletConnected, address } = useChain(walletChainName) + const { address } = useChain(walletChainName) + const { connected } = useConnect() const { signingClient } = useClients(walletChainName) const setTransactionState = useSetRecoilState(transactionStatusState) const slippage = useRecoilValue(slippageAtom) @@ -55,7 +56,7 @@ export const useTokenSwap = ({ return useMutation( 'swapTokens', () => { - if (!isWalletConnected) { + if (!connected) { throw new Error('Please connect your wallet.') } diff --git a/components/Pages/Trade/Swap/hooks/useTransaction.tsx b/components/Pages/Trade/Swap/hooks/useTransaction.tsx index a69d6fba..53a945ce 100644 --- a/components/Pages/Trade/Swap/hooks/useTransaction.tsx +++ b/components/Pages/Trade/Swap/hooks/useTransaction.tsx @@ -2,8 +2,8 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { useMutation, useQuery, useQueryClient } from 'react-query' import { useToast } from '@chakra-ui/react' -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate'; +import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import type { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate'; import Finder from 'components/Finder' import { directTokenSwap } from 'components/Pages/Trade/Swap/hooks/directTokenSwap' import { ChainId } from 'constants/index' diff --git a/components/Wallet/ChainSelect/ChainList/ChainItem.tsx b/components/Wallet/ChainSelect/ChainList/ChainItem.tsx index 9a7d98b3..bde2e111 100644 --- a/components/Wallet/ChainSelect/ChainList/ChainItem.tsx +++ b/components/Wallet/ChainSelect/ChainList/ChainItem.tsx @@ -3,6 +3,7 @@ import { BsCircleFill } from 'react-icons/bs' import { useQueryClient } from 'react-query' import { Box, HStack, Image, ListIcon, ListItem, Text, Tooltip } from '@chakra-ui/react' +import { WalletType } from 'components/Wallet/Modal/WalletModal'; import { kBg } from 'constants/visualComponentConstants' const ChainItem = ({ @@ -28,7 +29,7 @@ const ChainItem = ({ whiteSpace="pre-wrap" > To access this chain, you must add it to your wallet. - ) : !walletConnected && chain.chainName?.includes('Injective') && walletType !== 'station-extension' ? ( + ) : !walletConnected && chain.chainName?.includes('Injective') && walletType !== WalletType.terraExtension ? ( { const chains = useChainInfos(); - const walletType = window.localStorage.getItem(COSMOS_KIT_WALLET_KEY); + const { wallet } = useConnect(); - const connectedChains = []; - const removedChains = []; + const connectedChains = useMemo(() => chains.filter((chain) => { + const isChainConnected = + wallet?.options.wallet_name === WalletType.leapSnap + ? chain.coinType === 118 + : connectedChainIds.includes(chain.chainId); + + return isChainConnected; + }), + [chains, wallet, connectedChainIds]); - chains.forEach((chain) => { + const removedChains = useMemo(() => chains.filter((chain) => { const isChainConnected = - walletType === WalletType.leapSnap + wallet?.options.wallet_name === WalletType.leapSnap ? chain.coinType === 118 : connectedChainIds.includes(chain.chainId); - if (isChainConnected) { - connectedChains.push(chain); - } else { - removedChains.push(chain); - } - }); + return !isChainConnected; + }), + [chains, wallet, connectedChainIds]); return [connectedChains, removedChains]; }; -const ChainList = ({ onChange, onClose, currentChainState, connectedChainIds }) => { - const walletType = window.localStorage.getItem(COSMOS_KIT_WALLET_KEY); +const ChainList = ({ + onChange, + onClose, + currentChainState, + connectedChainIds, +}) => { + const { wallet } = useConnect(); const [connectedChains, removedChains] = useFilteredChains(connectedChainIds); return ( @@ -44,7 +53,7 @@ const ChainList = ({ onChange, onClose, currentChainState, connectedChainIds }) onClose={onClose} active={currentChainState?.chainId === chain?.chainId} walletConnected={true} - walletType={walletType} + walletType={wallet?.options.wallet_name} /> ))} {removedChains.map((chain) => ( @@ -55,7 +64,7 @@ const ChainList = ({ onChange, onClose, currentChainState, connectedChainIds }) onClose={onClose} active={currentChainState?.chainId === chain?.chainId} walletConnected={false} - walletType={walletType} + walletType={wallet?.options.wallet_name} /> ))} diff --git a/components/Wallet/ChainSelect/NetworkForm/NetworkForm.tsx b/components/Wallet/ChainSelect/NetworkForm/NetworkForm.tsx index 6692f446..aa9ee739 100644 --- a/components/Wallet/ChainSelect/NetworkForm/NetworkForm.tsx +++ b/components/Wallet/ChainSelect/NetworkForm/NetworkForm.tsx @@ -3,21 +3,17 @@ import React from 'react' import { FormControl, FormLabel, Text } from '@chakra-ui/react' import NetworkSwitch from 'components/Wallet/ChainSelect/NetworkForm/NetworkSwitch' -function NetworkForm() { - return ( - - - - Testnet - - - - - ) -} +const NetworkForm = () => + + + Testnet + + + + export default NetworkForm diff --git a/components/Wallet/ChainSelect/NetworkForm/NetworkSwitch.tsx b/components/Wallet/ChainSelect/NetworkForm/NetworkSwitch.tsx index 48902ebb..71c1eb96 100644 --- a/components/Wallet/ChainSelect/NetworkForm/NetworkSwitch.tsx +++ b/components/Wallet/ChainSelect/NetworkForm/NetworkSwitch.tsx @@ -1,8 +1,11 @@ import { useQueryClient } from 'react-query' import { Switch } from '@chakra-ui/react' +import { useConnect } from '@quirks/react' +import { store } from '@quirks/store' import defaultTokens from 'components/Pages/Trade/Swap/defaultTokens.json' import { tokenSwapAtom } from 'components/Pages/Trade/Swap/swapAtoms' +import { assetsLists, chains, testnetAssetsLists, testnetChains } from 'constants/chains' import { MAINNET_TESTNET_CHAIN_ID_MAP, NETWORK_MAP, WALLET_CHAIN_NAME_MAINNET_TESTNET_MAP } from 'constants/index' import { useRecoilState } from 'recoil' import { NetworkType, chainState } from 'state/chainState' @@ -13,6 +16,7 @@ export const NetworkSwitch = () => { const [currentChainState, setCurrentChainState] = useRecoilState(chainState) const [_, setTokenSwapState] = useRecoilState(tokenSwapAtom) + const { disconnect, connected } = useConnect(); const changeNetwork = () => { queryClient.clear() @@ -31,10 +35,26 @@ export const NetworkSwitch = () => { // eslint-disable-next-line prefer-destructuring const updatedChainName = updatedChainId.split('-')[0] + const network = NetworkType[updatedNetwork]; + const currentWalletName = store.getState().walletName; + + if (connected) { + disconnect(); + } + + store.setState({ + chains: network === NetworkType.testnet ? testnetChains : chains, + assetsLists: network === NetworkType.testnet ? testnetAssetsLists : assetsLists, + }) + + if (currentWalletName) { + store.getState().connect(currentWalletName); + } + setCurrentChainState({ ...currentChainState, chainName: updatedChainName, - network: NetworkType[updatedNetwork], + network, chainId: updatedChainId, walletChainName: updatedWalletChainName, }) diff --git a/components/Wallet/ConnectedWalletWithDisconnect/ConnectedWallet/ConnectedWallet.tsx b/components/Wallet/ConnectedWalletWithDisconnect/ConnectedWallet/ConnectedWallet.tsx index 20ea2682..86bddc65 100644 --- a/components/Wallet/ConnectedWalletWithDisconnect/ConnectedWallet/ConnectedWallet.tsx +++ b/components/Wallet/ConnectedWalletWithDisconnect/ConnectedWallet/ConnectedWallet.tsx @@ -1,7 +1,7 @@ import React from 'react' import { Button, HStack, useToast } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import { ConnectedWalletIcon, } from 'components/Wallet/ConnectedWalletWithDisconnect/ConnectedWallet/ConnectedWalletIcon' diff --git a/components/Wallet/ConnectedWalletWithDisconnect/ConnectedWallet/ConnectedWalletIcon.tsx b/components/Wallet/ConnectedWalletWithDisconnect/ConnectedWallet/ConnectedWalletIcon.tsx index 90b12b14..586eedbe 100644 --- a/components/Wallet/ConnectedWalletWithDisconnect/ConnectedWallet/ConnectedWalletIcon.tsx +++ b/components/Wallet/ConnectedWalletWithDisconnect/ConnectedWallet/ConnectedWalletIcon.tsx @@ -1,38 +1,15 @@ import React from 'react' -import { useChain } from '@cosmos-kit/react-lite' -import CosmostationWalletIcon from 'components/Icons/CosmostationWalletIcon' -import KeplrWalletIcon from 'components/Icons/KeplrWalletIcon' -import LeapSnapIcon from 'components/Icons/LeapSnapIcon' -import LeapWalletIcon from 'components/Icons/LeapWalletIcon' -import NinjiWalletIcon from 'components/Icons/NinjiWalletIcon' -import OKXWalletIcon from 'components/Icons/OKXWalletIcon' -import TerraExtensionIcon from 'components/Icons/TerraExtensionIcon' -import { WalletType } from 'components/Wallet/Modal/WalletModal' -import { useRecoilValue } from 'recoil' -import { chainState } from 'state/chainState' - +import { useConnect } from '@quirks/react' +import Image from 'next/image' export const ConnectedWalletIcon = () => { - const { walletChainName } = useRecoilValue(chainState) - const { wallet } = useChain(walletChainName) - switch (wallet?.name) { - case WalletType.keplrExtension || WalletType.keplrMobile: - return - case WalletType.leapExtension || WalletType.leapMobile: - return - case WalletType.cosmoStationExtension || WalletType.cosmoStationMobile: - return - case WalletType.terraExtension: - return - case WalletType.leapSnap: - return - case WalletType.ninjiExtension: - return - case WalletType.okxwallet: - return - default: - return <> + const { wallet } = useConnect() + + if (!wallet) { + return null; } + + return {wallet.options.pretty_name} } diff --git a/components/Wallet/ConnectedWalletWithDisconnect/ConnectedWallet/TruncatedAddress.tsx b/components/Wallet/ConnectedWalletWithDisconnect/ConnectedWallet/TruncatedAddress.tsx index 3f4de7fa..12f806f5 100644 --- a/components/Wallet/ConnectedWalletWithDisconnect/ConnectedWallet/TruncatedAddress.tsx +++ b/components/Wallet/ConnectedWalletWithDisconnect/ConnectedWallet/TruncatedAddress.tsx @@ -1,7 +1,7 @@ import React from 'react' import { Text } from '@chakra-ui/react' -import { useChain } from '@cosmos-kit/react-lite' +import { useChain } from '@quirks/react' import { useRecoilValue } from 'recoil' import { chainState } from 'state/chainState' import { truncate } from 'util/truncate' diff --git a/components/Wallet/Modal/WalletConnectButton.tsx b/components/Wallet/Modal/WalletConnectButton.tsx index 3e913b69..36ba2e53 100644 --- a/components/Wallet/Modal/WalletConnectButton.tsx +++ b/components/Wallet/Modal/WalletConnectButton.tsx @@ -1,17 +1,11 @@ import { useCallback } from 'react' import { Button, HStack, Text, useToast } from '@chakra-ui/react' -import CosmostationWalletIcon from 'components/Icons/CosmostationWalletIcon' -import KeplrWalletIcon from 'components/Icons/KeplrWalletIcon' -import LeapSnapIcon from 'components/Icons/LeapSnapIcon' -import LeapWalletIcon from 'components/Icons/LeapWalletIcon' -import NinjiWalletIcon from 'components/Icons/NinjiWalletIcon' -import OKXWalletIcon from 'components/Icons/OKXWalletIcon' -import { ShellWalletIcon } from 'components/Icons/ShellWalletIcon' -import { TerraStationWalletIcon } from 'components/Icons/TerraStationWalletIcon' +import { useConfig } from '@quirks/react' import { WalletConnectIcon } from 'components/Icons/WalletConnectIcon' import { WalletType } from 'components/Wallet/Modal/WalletModal' import { ACTIVE_NETWORKS } from 'constants/networks' +import Image from 'next/image' import { useRecoilValue } from 'recoil' import { chainState } from 'state/chainState' @@ -24,6 +18,8 @@ interface Props { export const WalletConnectButton = ({ onCloseModal, connect, walletType }: Props) => { const toast = useToast() const { network, chainId, chainName } = useRecoilValue(chainState) + const { wallets } = useConfig(); + const getKeplrChains = async (chains: Array) => { const response = await fetch('https://keplr-chain-registry.vercel.app/api/chains'); const registry = await response.json(); @@ -42,36 +38,10 @@ export const WalletConnectButton = ({ onCloseModal, connect, walletType }: Props isClosable: true, }); } - const setWallet = useCallback(async () => { - let error = false - if (walletType === WalletType.keplrExtension && window.keplr) { - const connected = (await window.keplr?.getChainInfosWithoutEndpoints()).map((elem) => elem.chainId) - const keplrChains: any[] = await getKeplrChains(Object.values(ACTIVE_NETWORKS[network])) - for (const chain of keplrChains) { - if (!connected?.includes(chain.chainId)) { - // eslint-disable-next-line no-await-in-loop - await window.keplr.experimentalSuggestChain(chain) - } - } - } - if ((walletType === WalletType.terraExtension || walletType === WalletType.keplrExtension)) { - const windowConnection = walletType === WalletType.terraExtension ? (window.station?.keplr) : (window?.keplr) - try { - await (windowConnection.getKey(chainId)) - } catch (e) { - error = true - console.error(`${chainId} not activated`) - handleChainActivationError(chainName, toast); - } - if (walletType === WalletType.terraExtension && chainName.includes('injective')) { - error = true - } - } - if (!error) { - connect() - } + const setWallet = useCallback(() => { + connect() onCloseModal() - }, [onCloseModal, connect, walletType]) + }, [onCloseModal, connect]) const renderContent = () => { switch (walletType) { @@ -103,32 +73,17 @@ export const WalletConnectButton = ({ onCloseModal, connect, walletType }: Props } const renderIcon = () => { - switch (walletType) { - case WalletType.keplrExtension: - return - case WalletType.keplrMobile: - return - case WalletType.terraExtension: - return - case WalletType.cosmoStationExtension: - return - case WalletType.cosmoStationMobile: - return - case WalletType.shellExtension: - return - case WalletType.leapExtension: - return - case WalletType.leapMobile: - return - case WalletType.leapSnap: - return - case WalletType.ninjiExtension: - return - case WalletType.okxwallet: - return - default: - return null + const wallet = wallets.find((wallet) => wallet.options.wallet_name === walletType); + + if (!wallet) { + return null; } + + if (wallet.options.connection_type === 'wallet_connect') { + return + } + + return {wallet.options.pretty_name}; } return ( diff --git a/components/Wallet/Modal/WalletModal.tsx b/components/Wallet/Modal/WalletModal.tsx index 46d35db7..18b53b1d 100644 --- a/components/Wallet/Modal/WalletModal.tsx +++ b/components/Wallet/Modal/WalletModal.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import { isMobile } from 'react-device-detect'; import { Modal, @@ -10,92 +9,45 @@ import { ModalOverlay, VStack, } from '@chakra-ui/react'; +import { useConfig, useConnect } from '@quirks/react'; import WalletConnectButton from 'components/Wallet/Modal/WalletConnectButton'; -import { useChainInfos } from 'hooks/useChainInfo'; -import { useRecoilValue } from 'recoil'; -import { chainState } from 'state/chainState'; +import { useWalletModal } from 'hooks/useWalletModal'; export enum WalletType { - keplrExtension = 'keplr-extension', - keplrMobile = 'keplr-mobile', - terraExtension = 'station-extension', - shellExtension = 'shell-extension', - leapExtension = 'leap-extension', - leapMobile = 'leap-cosmos-mobile', - leapSnap = 'leap-metamask-cosmos-snap', - cosmoStationExtension = 'cosmostation-extension', - cosmoStationMobile = 'cosmostation-mobile', - ninjiExtension = 'ninji-extension', - okxwallet = 'okxwallet-extension', + keplrExtension = 'keplrextension', + keplrMobile = 'keplrmobile', + terraExtension = 'stationextension', + shellExtension = 'shellextension', + leapExtension = 'leapextension', + leapMobile = 'leapmobile', + leapSnap = 'leapmetamasksnap', + cosmoStationExtension = 'cosmostationextention', + cosmoStationMobile = 'cosmostation', + ninjiExtension = 'ninjiextension', + okxwallet = 'okxextension', } -export const WalletModal = ({ isOpen, setOpen, walletRepo }) => { - const { chainId } = useRecoilValue(chainState); - const chainInfos: any = useChainInfos(); - const snap = Boolean(chainInfos.find((elem: { chainId: string; coinType: number; }) => elem.chainId === chainId && elem.coinType === 118)); - const onCloseModal = () => { - if (isOpen) { - setOpen(false); - } - } - - const shouldRenderButton = (wallet: { walletName: string, isModeExtension: boolean }) => { - const { walletName } = wallet - const okxchains = ["osmosis-1","jun-1","pacific-1"] - const inAppLeap = isMobile && window.leap && window.leap.mode === 'mobile-web' - const inAppKeplr = isMobile && window.keplr && window.keplr.mode === 'mobile-web' && !inAppLeap - const inj = chainId.includes('injective') && (walletName === WalletType.keplrExtension || walletName === WalletType.leapExtension || walletName === WalletType.ninjiExtension) - if (walletName === WalletType.okxwallet && !okxchains.includes(chainId)){ - return false - } - if (inj) { - return true - } else if (chainId.includes('injective') && !inAppLeap) { - return false - } else if (walletName === WalletType.ninjiExtension && !chainId.includes('injective')) { - return false - } - if (inj && inAppLeap && walletName === WalletType.leapExtension) { - return true; - } - if (inAppLeap && walletName === WalletType.leapExtension) { - return true; - } - if (inAppKeplr && walletName === WalletType.keplrExtension) { - return true; - } - if (inAppKeplr && walletName === WalletType.keplrExtension) { - return true; - } - if (!inAppLeap && walletName.toLowerCase().includes('metamask') && !snap) { - return false; - } - if (!(inAppLeap || inAppKeplr) && isMobile && !wallet.isModeExtension) { - return true; - } - if (!(inAppLeap || inAppKeplr) && !isMobile && wallet.isModeExtension) { - return true; - } - } +export const WalletModal = () => { + const { open, closeModal } = useWalletModal(); + const { wallets } = useConfig(); + const { connect } = useConnect(); return ( - + Select Wallet - {walletRepo?.wallets.map((wallet) => { - const { connect, walletName } = wallet; - if (!shouldRenderButton(wallet)) { - return null - } + {wallets.map((wallet) => { + const { wallet_name: walletName } = wallet.options; + return ( connect(walletName)} walletType={walletName as WalletType} /> ); diff --git a/components/Wallet/Wallet.tsx b/components/Wallet/Wallet.tsx index ba6fc819..24a58e8d 100644 --- a/components/Wallet/Wallet.tsx +++ b/components/Wallet/Wallet.tsx @@ -2,7 +2,7 @@ import { useEffect, useMemo, useState } from 'react' import { useQueryClient } from 'react-query' import { Box, Button, Divider, HStack, Text } from '@chakra-ui/react' -import { useChains } from '@cosmos-kit/react-lite' +import { useConnect } from '@quirks/react' import Card from 'components/Card' import WalletIcon from 'components/Icons/WalletIcon' import defaultTokens from 'components/Pages/Trade/Swap/defaultTokens.json' @@ -23,6 +23,7 @@ import { } from 'constants/index' import { useChainInfo, useChainInfos } from 'hooks/useChainInfo' import { useTokenList } from 'hooks/useTokenList' +import { useWalletModal } from 'hooks/useWalletModal' import { useRouter } from 'next/router' import { useRecoilState } from 'recoil' import { chainState, NetworkType } from 'state/chainState' @@ -38,24 +39,14 @@ const Wallet = () => { const [walletChains, setWalletChains] = useState([]) const chainName = useMemo(() => window.location.pathname.split('/')[1].split('/')[0], [window.location.pathname]) const [currentConnectedChainIds, setCurrentConnectedChainIds] = useState([]) - const allChains = useChains(walletChains) + const { disconnect, connected } = useConnect(); + const { openModal } = useWalletModal(); const router = useRouter() const [tokenList] = useTokenList() const [chainInfo] = useChainInfo(currentChainState.chainId) - const { isWalletConnected, disconnect, openView } = allChains[WALLET_CHAIN_NAMES_BY_CHAIN_ID[ACTIVE_NETWORKS[currentChainState.network][chainName]]] || {} const queryClient = useQueryClient() const [chainIdParam, setChainIdParam] = useState(null) - // Workaround for propagating isWalletConnected which apparently does not work as expected - useEffect(() => { - if (isWalletConnected) { - setCurrentChainState({ - ...currentChainState, - walletChainName: currentChainState.walletChainName, - }) - } - }, [isWalletConnected]) - useEffect(() => { if (chainName && currentChainState.network === NetworkType.mainnet) { setCurrentChainState({ @@ -224,7 +215,7 @@ const Wallet = () => { }, ] setTokenSwapState(newState) - if (isWalletConnected) { + /* if (isWalletConnected) { const newChain = allChains[WALLET_CHAIN_NAMES_BY_CHAIN_ID[chain.chainId]] const walletType = window.localStorage.getItem(COSMOS_KIT_WALLET_KEY) if (walletType !== WalletType.leapSnap && walletType !== WalletType.terraExtension && walletType !== WalletType.ninjiExtension) { @@ -232,7 +223,7 @@ const Wallet = () => { } else { resetWallet() } - } + } */ // eslint-disable-next-line react-hooks/rules-of-hooks } @@ -254,11 +245,12 @@ const Wallet = () => { } // eslint-disable-next-line react-hooks/exhaustive-deps }, [currentChainState.chainId, isInitialized]) - if (!isWalletConnected) { + + if (!connected) { return ( <> { color="white" borderColor="whiteAlpha.700" borderRadius="full" - onClick={openView} + onClick={openModal} > Connect @@ -285,7 +277,7 @@ const Wallet = () => { <> { + const { GasPrice } = await import('@cosmjs/stargate') if (CHAIN_NAMES.includes(chainName)) { const [feeTokens] = chain.fees.fee_tokens const price = feeTokens diff --git a/hooks/useClients.ts b/hooks/useClients.ts index 543d8da7..d7b6138a 100644 --- a/hooks/useClients.ts +++ b/hooks/useClients.ts @@ -1,42 +1,41 @@ import { useQueries } from 'react-query' -import { useChain } from '@cosmos-kit/react-lite' -import { InjectiveStargate } from '@injectivelabs/sdk-ts' -import { MsgExecuteContract } from 'cosmjs-types/cosmwasm/wasm/v1/tx'; +import { getEndpoint, assertIsDefined } from '@quirks/core' +import { useConnect } from '@quirks/react'; +import { getOfflineSigner, getSigningCosmWasmClient, store } from '@quirks/store'; + +const getCosmWasmClient = async (walletChainName: string) => { + const state = store.getState(); + + const chain = store.getState().chains.find((el) => el.chain_name === walletChainName); + assertIsDefined(chain); + const endpoint = getEndpoint(walletChainName, state.chains); + + const { CosmWasmClient } = await import('@cosmjs/cosmwasm-stargate'); + + return CosmWasmClient.connect(endpoint.rpc.address); +} export const useClients = (walletChainName: string) => { - const { - getCosmWasmClient, - getSigningCosmWasmClient, - isWalletConnected, - setDefaultSignOptions, - wallet, - getOfflineSignerDirect } = useChain(walletChainName) - if (isWalletConnected && wallet?.name !== 'station-extension') { - try { - setDefaultSignOptions({ - preferNoSetFee: true, - preferNoSetMemo: true, - disableBalanceCheck: true, - }) - } catch { - console.error(`unable to set Default option for: ${wallet.name}`) - } - } + const { connected } = useConnect(); + const queries = useQueries([ { queryKey: ['cosmWasmClient', walletChainName], - queryFn: async () => await getCosmWasmClient(), + queryFn: async () => await getCosmWasmClient(walletChainName), }, { queryKey: ['signingClient', walletChainName], - queryFn: async () => await getSigningCosmWasmClient(), - enabled: isWalletConnected, + queryFn: async () => await getSigningCosmWasmClient(walletChainName), + enabled: connected, }, { queryKey: ['injectiveSigningClient'], queryFn: async () => { try { - const offlineSigner: any = await getOfflineSignerDirect() + const { InjectiveStargate } = await import('@injectivelabs/sdk-ts') + const { MsgExecuteContract } = await import('cosmjs-types/cosmwasm/wasm/v1/tx') + const offlineSigner: any = await getOfflineSigner(walletChainName, 'direct'); + const client = await InjectiveStargate.InjectiveSigningStargateClient.connectWithSigner('https://sentry.tm.injective.network:443', offlineSigner) client.registry.register('/cosmwasm.wasm.v1.MsgExecuteContract', MsgExecuteContract) @@ -45,7 +44,7 @@ export const useClients = (walletChainName: string) => { return null } }, - enabled: isWalletConnected, + enabled: connected, }, ]) diff --git a/hooks/useSimulate.ts b/hooks/useSimulate.ts index 1492d615..35dabe4e 100644 --- a/hooks/useSimulate.ts +++ b/hooks/useSimulate.ts @@ -1,8 +1,8 @@ import { useQuery } from 'react-query' -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { EncodeObject } from '@cosmjs/proto-signing' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' +import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import type { EncodeObject } from '@cosmjs/proto-signing' +import type { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' import { ChainId } from 'constants/index' import { useRecoilState } from 'recoil' import { txRecoilState } from 'state/txRecoilState' diff --git a/hooks/useTokenBalance.tsx b/hooks/useTokenBalance.tsx index 482ebf50..42b09691 100644 --- a/hooks/useTokenBalance.tsx +++ b/hooks/useTokenBalance.tsx @@ -1,9 +1,9 @@ import { useMemo } from 'react' import { useQuery } from 'react-query' -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { useChain } from '@cosmos-kit/react-lite' +import type { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import { useChain, useConnect } from '@quirks/react' import { useConfig } from 'components/Pages/Bonding/hooks/useDashboardData' import { DEFAULT_TOKEN_BALANCE_REFETCH_INTERVAL } from 'constants/index' import { useClients } from 'hooks/useClients' @@ -103,7 +103,8 @@ export const useTokenBalance = (tokenSymbol: string) => { export const useMultipleTokenBalance = (tokenSymbols?: Array, isBonding?: boolean) => { const { network, chainId, walletChainName } = useRecoilValue(chainState) const { cosmWasmClient, signingClient } = useClients(walletChainName) - const { address, isWalletConnected } = useChain(walletChainName) + const { address } = useChain(walletChainName) + const { connected } = useConnect() const [tokenList] = useTokenList() const config = useConfig(network, chainId) const [ibcAssetsList] = useIBCAssetList() @@ -133,7 +134,7 @@ export const useMultipleTokenBalance = (tokenSymbols?: Array, isBonding? {}, }))), { - enabled: Boolean(isWalletConnected && + enabled: Boolean(connected && tokenSymbols?.length && tokenList?.tokens && cosmWasmClient), diff --git a/hooks/useTransaction.tsx b/hooks/useTransaction.tsx index 77e69a40..812efa73 100644 --- a/hooks/useTransaction.tsx +++ b/hooks/useTransaction.tsx @@ -2,8 +2,8 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { useMutation, useQuery, useQueryClient } from 'react-query' import { useToast } from '@chakra-ui/react' -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' +import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import type { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' import { directTokenSwap } from 'components/Pages/Trade/Swap/hooks/directTokenSwap' import { ChainId } from 'constants/index' import { TxStep } from 'types/index' diff --git a/hooks/useTxStatus.tsx b/hooks/useTxStatus.tsx index 71d2733c..0e09084c 100644 --- a/hooks/useTxStatus.tsx +++ b/hooks/useTxStatus.tsx @@ -2,8 +2,8 @@ import { useEffect } from 'react' import { useQueryClient } from 'react-query' import { useToast } from '@chakra-ui/react' -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' +import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import type { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate' import Finder from 'components/Finder' import useTxInfo from 'hooks/useTxInfo' import { useRecoilState } from 'recoil' diff --git a/hooks/useWalletModal.ts b/hooks/useWalletModal.ts new file mode 100644 index 00000000..fece0907 --- /dev/null +++ b/hooks/useWalletModal.ts @@ -0,0 +1,22 @@ +import { useCallback } from 'react'; + +import { useRecoilState } from 'recoil'; +import { walletModalState } from 'state/walletModalState'; + +export const useWalletModal = () => { + const [state, setModalState] = useRecoilState(walletModalState); + + const closeModal = useCallback(() => { + setModalState({ open: false }); + }, [setModalState]); + + const openModal = useCallback(() => { + setModalState({ open: true }); + }, [setModalState]); + + return { + closeModal, + openModal, + ...state, + }; +}; diff --git a/next.config.js b/next.config.js index 1a88ddf6..c45c36c1 100644 --- a/next.config.js +++ b/next.config.js @@ -1,10 +1,9 @@ +const million = require('million/compiler') const withBundleAnalyzer = require('@next/bundle-analyzer')({ enabled: process.env.ANALYZE === 'true', }) - - /** * @0xFable - Suppress errant recoil errors which seem to occur due to hot reloading * When using the app there is constant recoil warnings in the logs that users could see which indicate @@ -88,7 +87,7 @@ const config = { }, ]; }, - reactStrictMode: false, + reactStrictMode: true, // TODO: Needed to disabled all build error checking and eslint checking due to error with usage of Controller component, to fix that needs to be fixed typescript: { // !! WARN !! @@ -106,6 +105,14 @@ const config = { images: { loader: 'cloudinary', path: 'https://res.cloudinary.com/dk8s7xjsl/image/upload/', + remotePatterns: [ + { + protocol: 'https', + hostname: 'raw.githubusercontent.com', + port: '', + pathname: '/**', + }, + ], }, webpack(config, { webpack }) { config.plugins.push( @@ -131,4 +138,8 @@ const config = { }, } -module.exports = withBundleAnalyzer(config) +const millionConfig = { + auto: true,// if you're using RSC: auto: { rsc: true }, +}; + +module.exports = million.next(withBundleAnalyzer(config), millionConfig) diff --git a/package.json b/package.json index 97242ebc..56f880e7 100644 --- a/package.json +++ b/package.json @@ -22,24 +22,20 @@ "@cosmjs/encoding": "0.32.2", "@cosmjs/launchpad": "0.27.1", "@cosmjs/proto-signing": "0.32.2", - "@cosmos-kit/cosmostation": "^2.6.10", - "@cosmos-kit/keplr": "^2.6.9", - "@cosmos-kit/leap": "^2.6.9", - "@cosmos-kit/ninji": "^2.6.9", - "@cosmos-kit/okxwallet": "^2.4.9", - "@cosmos-kit/react-lite": "^2.6.9", - "@cosmos-kit/shell": "^2.6.9", - "@cosmos-kit/station": "^2.5.9", "@emotion/react": "^11", "@emotion/styled": "^11", "@injectivelabs/sdk-ts": "^1.14.5", + "@nabla-studio/chain-registry": "^0.10.0", "@next/bundle-analyzer": "^14.1.0", + "@quirks/core": "^0.15.1", + "@quirks/react": "^0.13.3", + "@quirks/store": "^0.22.1", + "@quirks/wallets": "^0.16.0", "@tanstack/react-table": "^8.12.0", "@terra-money/feather.js": "^2.0.4", "@typescript-eslint/eslint-plugin": "^6.19.0", "@typescript-eslint/parser": "^6.19.0", "bignumber.js": "^9.1.2", - "chain-registry": "^1.28.1", "dayjs": "^1.11.10", "eslint-plugin-import-helpers": "^1.3.1", "intercept-stdout": "^0.1.2", @@ -47,6 +43,7 @@ "jsoneditor": "^10.0.1", "junoblocks": "^0.2.93", "lodash": "^4.17.21", + "million": "latest", "next": "13.4.0", "numeral": "^2.0.6", "react": "^18.2.0", diff --git a/pages/_app.tsx b/pages/_app.tsx index 583a9ae3..ad938112 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -1,141 +1,83 @@ -import { FC, useEffect, useMemo, useState } from 'react' -import { Toaster } from 'react-hot-toast' -import { QueryClientProvider } from 'react-query' +import { Toaster } from 'react-hot-toast'; +import { QueryClientProvider } from 'react-query'; -import { CSSReset, ChakraProvider } from '@chakra-ui/react' -import { wallets as cosmoStationWallets } from '@cosmos-kit/cosmostation' -import { wallets as keplrWallets } from '@cosmos-kit/keplr' -import { wallets as leapWallets } from '@cosmos-kit/leap' -import { wallets as ninjiWallets } from '@cosmos-kit/ninji' -import { ChainProvider } from '@cosmos-kit/react-lite' -import { wallets as shellWallets } from '@cosmos-kit/shell' -import { wallets as stationWallets } from '@cosmos-kit/station' -import { wallets as okxwallet } from '@cosmos-kit/okxwallet' +import { CSSReset, ChakraProvider } from '@chakra-ui/react'; +import { QuirksConfig, QuirksNextProvider } from '@quirks/react'; +import type { Config } from '@quirks/store'; +import { + cosmostationExtension, + keplrExtension, + leapExtension, + okxExtension, + shellExtension, + stationExtension, +} from '@quirks/wallets'; +import 'theme/global.css'; +import AppLayout from 'components/Layout/AppLayout'; +import WalletModal from 'components/Wallet/Modal/WalletModal'; +import { chains, assetsLists } from 'constants/chains'; +import type { AppProps } from 'next/app'; +import Head from 'next/head'; +import Script from 'next/script'; +import { RecoilRoot } from 'recoil'; +import { queryClient } from 'services/queryClient'; +import theme from 'theme'; -import version from 'app_version.json' -import { chains, assets } from 'chain-registry' -import 'theme/global.css' -import AppLoading from 'components/AppLoading' -import AppLayout from 'components/Layout/AppLayout' -import WalletModal from 'components/Wallet/Modal/WalletModal' -import { endpointOptions } from 'constants/endpointOptions' -import { signerOptions } from 'constants/signerOptions' -import type { AppProps } from 'next/app' -import Head from 'next/head' -import Script from 'next/script' -import { RecoilRoot } from 'recoil' -import { queryClient } from 'services/queryClient' -import theme from 'theme' - -const MyApp: FC = ({ - Component, - pageProps, -}: AppProps) => { - const [mounted, setMounted] = useState(false) - - const walletProviders = [ - { - name: 'keplr', - wallet: keplrWallets, - }, - { - name: 'station', - wallet: stationWallets, - }, - { - name: 'leap', - wallet: leapWallets, - }, - { - name: 'ninji', - wallet: ninjiWallets, - }, - { - name: 'shellwallet', - wallet: shellWallets, - }, - { - name: 'cosmostationWallet', - wallet: cosmoStationWallets, - }, - { - name: 'okxwallet', - wallet: okxwallet, +const config: Config = { + wallets: [ + keplrExtension, + stationExtension, + leapExtension, + shellExtension, + cosmostationExtension, + okxExtension, + ], + chains, + assetsLists, + signOptions: { + preferNoSetFee: true, + preferNoSetMemo: true, + disableBalanceCheck: true, + }, + walletConnectOptions: { + providerOpts: { + projectId: 'a8510432ebb71e6948cfd6cde54b70f7', + metadata: { + name: 'White Whale', + description: 'test', + url: 'https://app.whitewhale.money/', + icons: [ + 'https://raw.githubusercontent.com/cosmology-tech/cosmos-kit/main/packages/docs/public/favicon-96x96.png', + ], + }, }, - ]; + }, +}; - const reorderWallets = useMemo(() => { - const newWallets: any[] = []; - const newUnavailableWallets: any[] = []; - try { - walletProviders.forEach(({ name, wallet }) => { - if (!window?.[name]) { - newUnavailableWallets.push(...wallet); - } else { - newWallets.push(...wallet); - } - }); - return [...newWallets, ...newUnavailableWallets]; - } catch { - return [] - } - }, []); - useEffect(() => { - const localVersion = localStorage.getItem('ww-version'); - if (!localVersion || version?.version !== localVersion) { - localStorage.clear() - localStorage.setItem('ww-version', version?.version) - } - setMounted(true) - }, [reorderWallets]) - return ( - <><> - - - - - - - +const App = ({ Component, pageProps }: AppProps) => ( + <> + + + + + + + + - {!mounted ? ( - - ) : ( - - - - )} - - - - {/* */} - - -