Skip to content

Commit

Permalink
Merge pull request #210 from cosmology-tech/eason/interchainjs
Browse files Browse the repository at this point in the history
Eason/interchainjs
  • Loading branch information
sdqede authored Oct 8, 2024
2 parents af8dfdc + e342b89 commit 86a9734
Show file tree
Hide file tree
Showing 643 changed files with 79 additions and 241,483 deletions.
4 changes: 3 additions & 1 deletion examples/injective/components/react/address-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
useColorMode,
Image
} from "@chakra-ui/react";
import { WalletStatus } from 'cosmos-kit';
// import { WalletStatus } from 'cosmos-kit';
import { WalletState as WalletStatus } from '@interChain-kit/core'
import { FaCheckCircle } from 'react-icons/fa';
import { FiCopy } from 'react-icons/fi';
import React, { ReactNode, useEffect, useState } from "react";
Expand Down Expand Up @@ -90,6 +91,7 @@ export const ConnectedShowAddress = ({
}, [address]);

return (
// @ts-ignore
<Button
title={address}
variant="unstyled"
Expand Down
10 changes: 3 additions & 7 deletions examples/injective/components/react/wallet-connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Button, Icon, Stack, Text, useColorModeValue } from '@chakra-ui/react';
import { IoWallet } from 'react-icons/io5';
import { ConnectWalletType } from '../types';
import { FiAlertTriangle } from 'react-icons/fi';
import { WalletStatus } from 'cosmos-kit';
// import { WalletStatus } from 'cosmos-kit';
import { WalletState as WalletStatus } from '@interChain-kit/core'

export const ConnectWalletButton = ({
buttonText,
Expand All @@ -13,6 +14,7 @@ export const ConnectWalletButton = ({
onClickConnectBtn
}: ConnectWalletType) => {
return (
// @ts-ignore
<Button
w="full"
minW="fit-content"
Expand Down Expand Up @@ -189,12 +191,6 @@ export const WalletConnectComponent = ({
return <>{connecting}</>;
case WalletStatus.Connected:
return <>{connected}</>;
case WalletStatus.Rejected:
return <>{rejected}</>;
case WalletStatus.Error:
return <>{error}</>;
case WalletStatus.NotExist:
return <>{notExist}</>;
default:
return <>{disconnect}</>;
}
Expand Down
11 changes: 6 additions & 5 deletions examples/injective/components/react/warn-block.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { ReactNode } from 'react';
import { Box, Stack, Text, useColorModeValue } from '@chakra-ui/react';
import { WalletStatus } from 'cosmos-kit';
// import { WalletStatus } from 'cosmos-kit';
import { WalletState as WalletStatus } from '@interChain-kit/core'

export const WarnBlock = ({
wordOfWarning,
Expand Down Expand Up @@ -80,10 +81,10 @@ export const ConnectStatusWarn = ({
error: ReactNode;
}) => {
switch (walletStatus) {
case WalletStatus.Rejected:
return <>{rejected}</>;
case WalletStatus.Error:
return <>{error}</>;
// case WalletStatus.Rejected:
// return <>{rejected}</>;
// case WalletStatus.Error:
// return <>{error}</>;
default:
return <></>;
}
Expand Down
49 changes: 29 additions & 20 deletions examples/injective/components/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {
} from '../components';
import { chainName } from '../config';
import { useWalletManager, useWalletModal } from '@interchain-kit/react'
import { WalletStatus } from 'cosmos-kit';
import { WalletState } from '@interChain-kit/core'
// import { WalletStatus } from 'cosmos-kit';
import { keplrWallet } from '@interchain-kit/keplr-extension'

export const WalletSection = () => {
Expand All @@ -37,10 +38,19 @@ export const WalletSection = () => {
const { open, close, modalIsOpen } = useWalletModal()
// const wallet = walletManager.wallets.find(item => item.option?.name === 'keplr-extension')

let { wallet } = useChain(chainName)
let {
connect,
openView,
status,
message,
wallet,
chain: chainInfo,
logoUrl,
} = useChain(chainName);
if (!wallet) {
wallet = keplrWallet
}
console.log('status from useChain', status)

const account = useAccount(chainName, wallet?.option?.name as string)
const username = account?.username
Expand All @@ -51,11 +61,12 @@ export const WalletSection = () => {
chainName,
label: wallet?.option?.prettyName,
value: chainName,
// icon: // logoUrl,
icon: logoUrl,
};

// Events
const onClickConnect: MouseEventHandler = async (e) => {
openView()
console.log('onClickConnect', wallet?.option?.name)
// return
e.preventDefault();
Expand All @@ -65,44 +76,42 @@ export const WalletSection = () => {

const onDisconnect: MouseEventHandler = async (e) => {
console.log('onDisconnect', chainIds)
wallet?.disconnect(chainIds).then(() => {
walletManager.disconnect(wallet.option?.name!).then(() => {
console.log('disconnect success', wallet.walletState)
}).catch((err) => {
console.log('disconnect error', err)
})
}

// const onClickOpenView: MouseEventHandler = (e) => {
// e.preventDefault();
// openView();
// };
const onClickOpenView: MouseEventHandler = (e) => {
e.preventDefault();
openView();
};

// Components
const connectWalletButton = (
<WalletConnectComponent
walletStatus={!!address?.length ? WalletStatus.Connected : WalletStatus.Disconnected}
walletStatus={status}
disconnect={
<Disconnected buttonText="Connect Wallet" onClick={onClickConnect} />
<Disconnected buttonText="Connect Wallet" onClick={onClickOpenView} />
}
connecting={<Connecting />}
connected={<>
<Connected buttonText={'Disconnect'} onClick={onDisconnect} />
<Connected buttonText={'My Wallet'} onClick={onClickOpenView} />
</>}
rejected={<>
<Rejected buttonText="Reconnect" onClick={onClickConnect} />
<Rejected buttonText="Reconnect" onClick={onClickOpenView} />
</>}
error={<>
{/* <Error buttonText="Change Wallet" onClick={onClickOpenView} /> */}
<Error buttonText="Change Wallet" onClick={onClickOpenView} />
</>}
notExist={<>
{/* <NotExist buttonText="Install Wallet" onClick={onClickOpenView} /> */}
<NotExist buttonText="Install Wallet" onClick={onClickOpenView} />
</>}
/>
);

const connectWalletWarn = (
<ConnectStatusWarn
walletStatus={!!address?.length ? WalletStatus.Connected : WalletStatus.Disconnected}
walletStatus={status}
rejected={
<RejectedWarn
icon={<Icon as={FiAlertTriangle} mt={1} />}
Expand All @@ -123,7 +132,7 @@ export const WalletSection = () => {
);
const addressBtn = (
<CopyAddressBtn
walletStatus={address ? WalletStatus.Connected : WalletStatus.Disconnected}
walletStatus={address ? WalletState.Connected : WalletState.Disconnected}
connected={<ConnectedShowAddress address={address} isLoading={false} />}
/>
);
Expand All @@ -142,8 +151,8 @@ export const WalletSection = () => {
>
<GridItem marginBottom={'20px'}>
<ChainCard
prettyName={chain?.label || chainName}
// icon={chain?.icon}
prettyName={chainName}
icon={chain?.icon}
/>
</GridItem>
<GridItem px={6}>
Expand Down
12 changes: 6 additions & 6 deletions examples/injective/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@cosmology/connect-chain-with-telescope",
"name": "@cosmology/injective",
"version": "2.0.1",
"private": true,
"scripts": {
Expand Down Expand Up @@ -31,10 +31,10 @@
"@cosmos-kit/react": "2.17.0",
"@emotion/react": "11.10.6",
"@emotion/styled": "11.10.6",
"@interchain-kit/core": "0.0.1-beta.20",
"@interchain-kit/keplr-extension": "0.0.1-beta.20",
"@interchain-kit/leap-extension": "0.0.1-beta.20",
"@interchain-kit/react": "0.0.1-beta.20",
"@interchain-kit/core": "0.0.1-beta.23",
"@interchain-kit/keplr-extension": "0.0.1-beta.23",
"@interchain-kit/leap-extension": "0.0.1-beta.23",
"@interchain-kit/react": "0.0.1-beta.23",
"@interchain-ui/react": "^1.24.0",
"@interchain-ui/react-no-ssr": "^0.1.6",
"@interchainjs/cosmos-types": "0.0.1-beta.9",
Expand Down Expand Up @@ -73,4 +73,4 @@
"typescript": "^5.1.6"
},
"packageManager": "[email protected]"
}
}
6 changes: 5 additions & 1 deletion examples/injective/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ function CreateCosmosApp({ Component, pageProps }: AppProps) {
wallets={wallets}
signerOptions={{}}
endpointOptions={{
endpoints: {}
endpoints: {
'injective-1': {
rpc: ['https://sentry.tm.injective.network'],
}
}
}}
>
{/* @ts-ignore */}
Expand Down
14 changes: 3 additions & 11 deletions examples/injective/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useState } from 'react';
import Head from 'next/head';
import BigNumber from 'bignumber.js';
import { MsgSend } from '@interchainjs/cosmos-types/cosmos/bank/v1beta1/tx';
Expand Down Expand Up @@ -98,15 +98,11 @@ const COIN_DISPLAY_EXPONENT = coin.denom_units.find(

export default function Home() {
const { colorMode, toggleColorMode } = useColorMode();
const walletManager = useWalletManager()
console.log('walletManager.chains', walletManager.chains)
const keplrExtension = walletManager.wallets.find(w => w.option?.name === 'keplr-extension')
let { wallet } = useChain(chainName)
console.log('wallet?.walletState', wallet?.walletState)
if (!wallet) {
wallet = keplrWallet
}
const { signingCosmWasmClient: getSigningStargateClient, address } = useChainWallet(chainName, wallet?.option?.name as string)
const { address } = useChainWallet(chainName, wallet?.option?.name as string)

const [resp, setResp] = useState('');

Expand All @@ -122,10 +118,6 @@ export default function Home() {
rpcClient,
});

// useEffect(() => {
// console.log('wallet?.walletState', wallet?.walletState)
// }, [wallet?.walletState])

//@ts-ignore
const hooks = createRpcQueryHooks({ rpc: rpcClient });

Expand Down Expand Up @@ -211,7 +203,7 @@ export default function Home() {

<Center mb={16}>
<SendTokensCard
isConnectWallet={wallet?.walletState === 'Connected'}
isConnectWallet={wallet?.walletState === WalletState.Connected}
balance={isBalanceLoaded ? balance.toNumber() : 0}
isFetchingBalance={isFetchingBalance}
response={resp}
Expand Down
46 changes: 23 additions & 23 deletions examples/injective/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3822,10 +3822,10 @@ __metadata:
"@cosmos-kit/react": "npm:2.17.0"
"@emotion/react": "npm:11.10.6"
"@emotion/styled": "npm:11.10.6"
"@interchain-kit/core": "npm:0.0.1-beta.20"
"@interchain-kit/keplr-extension": "npm:0.0.1-beta.20"
"@interchain-kit/leap-extension": "npm:0.0.1-beta.20"
"@interchain-kit/react": "npm:0.0.1-beta.20"
"@interchain-kit/core": "npm:0.0.1-beta.23"
"@interchain-kit/keplr-extension": "npm:0.0.1-beta.23"
"@interchain-kit/leap-extension": "npm:0.0.1-beta.23"
"@interchain-kit/react": "npm:0.0.1-beta.23"
"@interchain-ui/react": "npm:^1.24.0"
"@interchain-ui/react-no-ssr": "npm:^0.1.6"
"@interchainjs/cosmos-types": "npm:0.0.1-beta.9"
Expand Down Expand Up @@ -5470,9 +5470,9 @@ __metadata:
languageName: node
linkType: hard

"@interchain-kit/core@npm:0.0.1-beta.20":
version: 0.0.1-beta.20
resolution: "@interchain-kit/core@npm:0.0.1-beta.20"
"@interchain-kit/core@npm:0.0.1-beta.23":
version: 0.0.1-beta.23
resolution: "@interchain-kit/core@npm:0.0.1-beta.23"
dependencies:
"@chain-registry/v2": "npm:^1.65.20"
"@chain-registry/v2-types": "npm:^0.49.6"
Expand All @@ -5491,35 +5491,35 @@ __metadata:
buffer: "npm:^6.0.3"
interchainjs: "npm:0.0.1-beta.14"
long: "npm:^5.2.3"
checksum: 10c0/e068f8cc501b289499d5b7e55710bd44064c2389e04b49e8573f213bf53a60141ffd538375aa5196e9510939862af9461732c41d828ac3b2fa807422d041b7af
checksum: 10c0/2cb5a5364b7dba430217988e6bc9830e145ab3f48ddf4d6beb76225930da1a6a6403d7ce67135e85cdf4f156e9e5458c57fdda61f9edace1ccbd243ae90417b5
languageName: node
linkType: hard

"@interchain-kit/keplr-extension@npm:0.0.1-beta.20":
version: 0.0.1-beta.20
resolution: "@interchain-kit/keplr-extension@npm:0.0.1-beta.20"
"@interchain-kit/keplr-extension@npm:0.0.1-beta.23":
version: 0.0.1-beta.23
resolution: "@interchain-kit/keplr-extension@npm:0.0.1-beta.23"
dependencies:
"@interchain-kit/core": "npm:0.0.1-beta.20"
"@interchain-kit/core": "npm:0.0.1-beta.23"
"@keplr-wallet/provider-extension": "npm:^0.12.102"
checksum: 10c0/f8bd11131754c8deb262df7c188e01831169f644832c12c07952a198ba9f2b18b87ff8c1e3127c51a23eaf9b00d8dc466dd0f58cd1270a54357d42c8936ad86a
checksum: 10c0/d432b9dbb850bdd436fbcb26b834eb7db4809b47992b52dc35094ab2493c88fa0b83f432dd46c0520064d0925786c058947f2b5caf06c883f22b15fa2759e1b2
languageName: node
linkType: hard

"@interchain-kit/leap-extension@npm:0.0.1-beta.20":
version: 0.0.1-beta.20
resolution: "@interchain-kit/leap-extension@npm:0.0.1-beta.20"
"@interchain-kit/leap-extension@npm:0.0.1-beta.23":
version: 0.0.1-beta.23
resolution: "@interchain-kit/leap-extension@npm:0.0.1-beta.23"
dependencies:
"@interchain-kit/core": "npm:0.0.1-beta.20"
checksum: 10c0/10f251990d63abee30d37383c96eb2b18fa973077e64f5b898963790213797dc9fd1fe39c44b101468e12466425bbfeae571efe9f003e3d986c3149658fd973c
"@interchain-kit/core": "npm:0.0.1-beta.23"
checksum: 10c0/fd23b06123e1e95753c8b13d59bf370dc5b06368608b57d2acba791018f25c5f1341b7f629a47823b2453812b29aa4feb2891956dfa9b3b92244d1d7aec61496
languageName: node
linkType: hard

"@interchain-kit/react@npm:0.0.1-beta.20":
version: 0.0.1-beta.20
resolution: "@interchain-kit/react@npm:0.0.1-beta.20"
"@interchain-kit/react@npm:0.0.1-beta.23":
version: 0.0.1-beta.23
resolution: "@interchain-kit/react@npm:0.0.1-beta.23"
dependencies:
"@chain-registry/v2-types": "npm:^0.49.6"
"@interchain-kit/core": "npm:0.0.1-beta.20"
"@interchain-kit/core": "npm:0.0.1-beta.23"
"@interchain-ui/react": "npm:1.24.0"
"@interchainjs/cosmos-types": "npm:0.0.1-beta.9"
"@interchainjs/injective": "npm:0.0.1-beta.13"
Expand All @@ -5528,7 +5528,7 @@ __metadata:
interchainjs: "npm:0.0.1-beta.14"
react: "npm:^18.3.1"
react-dom: "npm:^18.3.1"
checksum: 10c0/5ee420a1a7d40ccc7e25c9ea3eb85916a7edcb579fc998d0b6be8bd242473a33bb7a9d08d29764e20c9a6fb8a297138d47d4eb10e204dadc428781c5011e498d
checksum: 10c0/cad31588c95b3b6d1c6eaf392aa6a672d73ec26792e0930f5822b01983d6f2e0a86b849f1902c021c50853ae3ab3220c98985448e350224bc63e78e29e8315af
languageName: node
linkType: hard

Expand Down
3 changes: 0 additions & 3 deletions examples/interchainjs/.babelrc

This file was deleted.

3 changes: 0 additions & 3 deletions examples/interchainjs/.eslintrc.json

This file was deleted.

Loading

0 comments on commit 86a9734

Please sign in to comment.