import React, { FC } from 'react'; import { ChainProvider, useChain } from '@cosmos-kit/react'; import { assets, chains } from 'chain-registry'; import { wallets as keplr } from '@cosmos-kit/keplr-extension'; import { wallets as ledger } from '@cosmos-kit/ledger'; import Button from '@mui/material/Button'; import CircularProgress from '@mui/material/CircularProgress'; import Box from '@mui/material/Box'; import Typography from '@mui/material/Typography'; import { Alert, AlertTitle } from '@mui/material'; import { Wallet } from '@cosmos-kit/core'; import { CosmosKitLedger } from './ledger'; import { CosmosKitSign } from './sign'; import type { SignerOptions } from '@cosmos-kit/core'; const CosmosKitSetup: FC<{ children: React.ReactNode }> = ({ children }) => { const assetsFixedUp = React.useMemo(() => { const nyx = assets.find((a) => a.chain_name === 'nyx'); if (nyx) { const nyxCoin = nyx.assets.find((a) => a.name === 'nyx'); if (nyxCoin) { nyxCoin.coingecko_id = 'nyx'; } nyx.assets = nyx.assets.reverse(); } return assets; }, [assets]); const chainsFixedUp = React.useMemo(() => { const nyx = chains.find((c) => c.chain_id === 'nyx'); if (nyx) { if (!nyx.staking) { nyx.staking = { staking_tokens: [{ denom: 'unyx' }], lock_duration: { blocks: 10000, }, }; } } return chains; }, [chains]); // components/cosmos-kit/index.tsx return ( 'amino' }} throwErrors={false} > {children} ); }; function walletRejectMessageOrError(wallet?: Wallet, error?: React.ReactNode) { if (!wallet) { if (!error) { return undefined; } return error; } if (typeof wallet.rejectMessage === 'string') { return wallet.rejectMessage; } return wallet.rejectMessage.source; } const Wrapper: FC<{ children?: React.ReactNode; wallet?: Wallet; header?: React.ReactNode; error?: React.ReactNode; disconnect: () => Promise; }> = ({ wallet, disconnect, error, header, children }) => { if (error) { return ( {wallet && Failed to connect to {wallet.prettyName}} {wallet && walletRejectMessageOrError(wallet)} ); } return ( {header && header} {children} ); }; const CosmosKitInner = () => { const { wallet, address, connect, disconnect, isWalletConnecting, isWalletDisconnected, isWalletError, isWalletNotExist, isWalletRejected, } = useChain('nyx'); if (isWalletError) { return ; } if (isWalletNotExist) { return ; } if (isWalletRejected) { return ( ); } if (isWalletDisconnected) { return ( ); } if (isWalletConnecting) { return ; } // Ledger Hardware Wallet if (wallet.mode === 'ledger') { return ( Connected to {wallet.prettyName} Address: {address}{' '} } disconnect={disconnect} > ); } // Extension or Wallet Connect return ( Connected to {wallet.prettyName} Address: {address}{' '} } disconnect={disconnect} > ); }; export const CosmosKit = () => ( );