Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions examples/contracts/components/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useColorModeValue,
Text
} from '@chakra-ui/react';
import { MouseEventHandler, useEffect, useMemo } from 'react';
import { MouseEventHandler, useMemo } from 'react';
import { FiAlertTriangle } from 'react-icons/fi';
import {
Astronaut,
Expand All @@ -28,26 +28,28 @@ import {
ChainCard
} from '../components';
import { getWalletPrettyName } from '@cosmos-kit/config';
import { ChainName } from '@cosmos-kit/core';
import { assets as chainAssets } from 'chain-registry';
import { ChainRecord } from '@cosmos-kit/core';

export const WalletSection = ({ chainName }: { chainName?: ChainName }) => {
export const WalletSection = () => {
const walletManager = useWallet();
const {
connect,
openView,
setCurrentChain,
walletStatus,
username,
address,
message,
currentChainName,
currentWalletName,
chains
} = walletManager;

const chainOptions = useMemo(
() =>
chains.map((chainRecord) => {
const chainName = currentChainName;

const chain = useMemo(
() => {
const getChain = (chainRecord: ChainRecord) => {
const assets = chainAssets.find(
(_chain) => _chain.chain_name === chainRecord.name
)?.assets;
Expand All @@ -60,23 +62,16 @@ export const WalletSection = ({ chainName }: { chainName?: ChainName }) => {
: undefined,
disabled: false
};
}),
}
return getChain(chains[0]);
},
[chains]
);

const chain = chainOptions.find((c) => c.chainName === chainName);

useEffect(() => {
setCurrentChain(chainName);
}, [chainName, setCurrentChain]);

// Events
const onClickConnect: MouseEventHandler = async (e) => {
e.preventDefault();
openView();
if (currentWalletName) {
await connect();
}
await connect();
};

const onClickOpenView: MouseEventHandler = (e) => {
Expand Down
52 changes: 52 additions & 0 deletions examples/contracts/config/defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { StdFee } from '@cosmjs/amino';
import { assets } from 'chain-registry';
import { AssetList, Asset } from '@chain-registry/types';

export const chainName = 'osmosis';

export const chainassets: AssetList = assets.find(
(chain) => chain.chain_name === chainName
) as AssetList;

export const baseAsset: Asset = chainassets.assets.find(
(asset) => asset.base === 'uosmo'
) as Asset;

export const sendTokens = (
getStargateClient: () => Promise<SigningStargateClient>,
setResp: () => any,
address: string
) => {
return async () => {
const stargateClient = await getStargateClient();
if (!stargateClient || !address) {
console.error('stargateClient undefined or address undefined.');
return;
}

const { send } = cosmos.bank.v1beta1.MessageComposer.withTypeUrl;

const msg = send({
amount: [
{
denom: baseAsset.base,
amount: '1000'
}
],
toAddress: address,
fromAddress: address
});

const fee: StdFee = {
amount: [
{
denom: baseAsset.base,
amount: '0'
}
],
gas: '86364'
};
const response = await stargateClient.signAndBroadcast(address, [msg], fee);
setResp(JSON.stringify(response, null, 2));
};
};
1 change: 1 addition & 0 deletions examples/contracts/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './theme';
export * from './features';
export * from './defaults';
2 changes: 1 addition & 1 deletion examples/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@chakra-ui/react": "^2.3.4",
"@cosmjs/cosmwasm-stargate": "0.29.0",
"@cosmjs/stargate": "0.29.0",
"@cosmos-kit/react": "^0.18.1",
"@cosmos-kit/react": "0.18.4",
"@cosmos-kit/types": "^0.11.0",
"@emotion/react": "11.10.4",
"@emotion/styled": "11.10.4",
Expand Down
6 changes: 3 additions & 3 deletions examples/contracts/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '../styles/globals.css';
import type { AppProps } from 'next/app';
import { WalletProvider } from '@cosmos-kit/react';
import { ChakraProvider } from '@chakra-ui/react';
import { defaultTheme } from '../config';
import { chainName, defaultTheme } from '../config';
import { wallets } from '@cosmos-kit/keplr';
import { chains, assets } from 'chain-registry';
import { getSigningCosmosClientOptions } from '../codegen';
Expand Down Expand Up @@ -38,8 +38,8 @@ function CreateCosmosApp({ Component, pageProps }: AppProps) {
return (
<ChakraProvider theme={defaultTheme}>
<WalletProvider
chains={chains}
assetLists={assets}
chains={chains.filter(chain => chain.chain_name === chainName)}
assetLists={assets.filter(asset => asset.chain_name === chainName)}
wallets={wallets}
signerOptions={signerOptions}
>
Expand Down
58 changes: 2 additions & 56 deletions examples/contracts/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,76 +1,22 @@
import { Container, Button } from '@chakra-ui/react';
import { useWallet } from '@cosmos-kit/react';
import { useEffect, useState } from 'react';
import { StdFee } from '@cosmjs/amino';
import { assets } from 'chain-registry';
import { AssetList, Asset } from '@chain-registry/types';
import { useState } from 'react';
import { SigningStargateClient } from '@cosmjs/stargate';
import { WalletStatus } from '@cosmos-kit/core';
import BigNumber from 'bignumber.js';

import { WalletSection } from '../components';
import { cosmos } from '../codegen';

const chainName = 'osmosis';
const chainassets: AssetList = assets.find(
(chain) => chain.chain_name === chainName
) as AssetList;
const baseAsset: Asset = chainassets.assets.find(
(asset) => asset.base === 'uosmo'
) as Asset;

const sendTokens = (
getStargateClient: () => Promise<SigningStargateClient>,
setResp: () => any,
address: string
) => {
return async () => {
const stargateClient = await getStargateClient();
if (!stargateClient || !address) {
console.error('stargateClient undefined or address undefined.');
return;
}

const { send } = cosmos.bank.v1beta1.MessageComposer.withTypeUrl;

const msg = send({
amount: [
{
denom: baseAsset.base,
amount: '1000'
}
],
toAddress: address,
fromAddress: address
});

const fee: StdFee = {
amount: [
{
denom: baseAsset.base,
amount: '0'
}
],
gas: '86364'
};
const response = await stargateClient.signAndBroadcast(address, [msg], fee);
setResp(JSON.stringify(response, null, 2));
};
};
import { baseAsset, chainassets, chainName, sendTokens } from '../config';

export default function Home() {
const {
getStargateClient,
address,
setCurrentChain,
currentWallet,
walletStatus
} = useWallet();

useEffect(() => {
setCurrentChain(chainName);
}, [chainName]);

const [balance, setBalance] = useState(new BigNumber(0));
const [resp, setResp] = useState('');
const getBalance = async () => {
Expand Down
20 changes: 15 additions & 5 deletions examples/contracts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"target": "ES2020",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
Expand All @@ -15,6 +19,12 @@
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
31 changes: 13 additions & 18 deletions examples/juno/components/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useColorModeValue,
Text
} from '@chakra-ui/react';
import { MouseEventHandler, useEffect, useMemo } from 'react';
import { MouseEventHandler, useMemo } from 'react';
import { FiAlertTriangle } from 'react-icons/fi';
import {
Astronaut,
Expand All @@ -28,26 +28,28 @@ import {
ChainCard
} from '../components';
import { getWalletPrettyName } from '@cosmos-kit/config';
import { ChainName } from '@cosmos-kit/core';
import { assets as chainAssets } from 'chain-registry';
import { ChainRecord } from '@cosmos-kit/core';

export const WalletSection = ({ chainName }: { chainName?: ChainName }) => {
export const WalletSection = () => {
const walletManager = useWallet();
const {
connect,
openView,
setCurrentChain,
walletStatus,
username,
address,
message,
currentChainName,
currentWalletName,
chains
} = walletManager;

const chainOptions = useMemo(
() =>
chains.map((chainRecord) => {
const chainName = currentChainName;

const chain = useMemo(
() => {
const getChain = (chainRecord: ChainRecord) => {
const assets = chainAssets.find(
(_chain) => _chain.chain_name === chainRecord.name
)?.assets;
Expand All @@ -60,23 +62,16 @@ export const WalletSection = ({ chainName }: { chainName?: ChainName }) => {
: undefined,
disabled: false
};
}),
}
return getChain(chains[0]);
},
[chains]
);

const chain = chainOptions.find((c) => c.chainName === chainName);

useEffect(() => {
setCurrentChain(chainName);
}, [chainName, setCurrentChain]);

// Events
const onClickConnect: MouseEventHandler = async (e) => {
e.preventDefault();
openView();
if (currentWalletName) {
await connect();
}
await connect();
};

const onClickOpenView: MouseEventHandler = (e) => {
Expand Down
12 changes: 12 additions & 0 deletions examples/juno/config/defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { assets } from 'chain-registry';
import { AssetList, Asset } from '@chain-registry/types';

export const chainName = 'juno';

export const chainassets: AssetList = assets.find(
(chain) => chain.chain_name === chainName
) as AssetList;

export const coin: Asset = chainassets.assets.find(
(asset) => asset.base === 'ujuno'
) as Asset;
1 change: 1 addition & 0 deletions examples/juno/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './theme';
export * from './features';
export * from './defaults';
6 changes: 3 additions & 3 deletions examples/juno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"@chakra-ui/react": "2.3.4",
"@cosmjs/cosmwasm-stargate": "0.29.0",
"@cosmjs/stargate": "0.29.0",
"@cosmos-kit/core": "0.19.0",
"@cosmos-kit/keplr": "0.19.0",
"@cosmos-kit/react": "0.18.1",
"@cosmos-kit/core": "0.19.3",
"@cosmos-kit/keplr": "0.19.3",
"@cosmos-kit/react": "0.18.4",
"@emotion/react": "11.10.4",
"@emotion/styled": "11.10.4",
"@juno-network/assets": "0.11.1",
Expand Down
6 changes: 3 additions & 3 deletions examples/juno/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '../styles/globals.css';
import type { AppProps } from 'next/app';
import { WalletProvider } from '@cosmos-kit/react';
import { ChakraProvider } from '@chakra-ui/react';
import { defaultTheme } from '../config';
import { chainName, defaultTheme } from '../config';
import { wallets } from '@cosmos-kit/keplr';
import { assets, chains } from 'chain-registry';
import { getSigningCosmosClientOptions } from 'juno-network';
Expand All @@ -29,8 +29,8 @@ function CreateCosmosApp({ Component, pageProps }: AppProps) {
return (
<ChakraProvider theme={defaultTheme}>
<WalletProvider
chains={chains}
assetLists={assets}
chains={chains.filter(chain => chain.chain_name === chainName)}
assetLists={assets.filter(asset => asset.chain_name === chainName)}
wallets={wallets}
signerOptions={signerOptions}
>
Expand Down
Loading