Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update #23

Merged
merged 2 commits into from
Oct 17, 2022
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
57 changes: 21 additions & 36 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, useMemo } from 'react';
import { MouseEventHandler, useEffect } from 'react';
import { FiAlertTriangle } from 'react-icons/fi';
import {
Astronaut,
Expand All @@ -27,9 +27,8 @@ import {
WalletConnectComponent,
ChainCard
} from '../components';
import { getWalletPrettyName } from '@cosmos-kit/config';
import { assets as chainAssets } from 'chain-registry';
import { ChainRecord } from '@cosmos-kit/core';
import { chainName } from '../config';


export const WalletSection = () => {
const walletManager = useWallet();
Expand All @@ -41,32 +40,22 @@ export const WalletSection = () => {
address,
message,
currentChainName,
currentWalletName,
chains
currentWallet,
currentChainRecord,
getChainLogo,
setCurrentChain
} = walletManager;

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

const chain = useMemo(
() => {
const getChain = (chainRecord: ChainRecord) => {
const assets = chainAssets.find(
(_chain) => _chain.chain_name === chainRecord.name
)?.assets;
return {
chainName: chainRecord.name,
label: chainRecord.chain.pretty_name,
value: chainRecord.name,
icon: assets
? assets[0]?.logo_URIs?.svg || assets[0]?.logo_URIs?.png
: undefined,
disabled: false
};
}
return getChain(chains[0]);
},
[chains]
);
const chain = {
chainName: currentChainName,
label: currentChainRecord?.chain.pretty_name,
value: currentChainName,
icon: getChainLogo(currentChainName)
}

// Events
const onClickConnect: MouseEventHandler = async (e) => {
Expand Down Expand Up @@ -104,17 +93,13 @@ export const WalletSection = () => {
rejected={
<RejectedWarn
icon={<Icon as={FiAlertTriangle} mt={1} />}
wordOfWarning={`${getWalletPrettyName(
currentWalletName
)}: ${message}`}
wordOfWarning={`${currentWallet?.walletInfo.prettyName}: ${message}`}
/>
}
error={
<RejectedWarn
icon={<Icon as={FiAlertTriangle} mt={1} />}
wordOfWarning={`${getWalletPrettyName(
currentWalletName
)}: ${message}`}
wordOfWarning={`${currentWallet?.walletInfo.prettyName}: ${message}`}
/>
}
/>
Expand All @@ -123,7 +108,7 @@ export const WalletSection = () => {
const userInfo = (
<ConnectedUserInfo username={username} icon={<Astronaut />} />
);
const addressBtn = chainName && (
const addressBtn = currentChainName && (
<CopyAddressBtn
walletStatus={walletStatus}
connected={<ConnectedShowAddress address={address} isLoading={false} />}
Expand All @@ -140,10 +125,10 @@ export const WalletSection = () => {
alignItems="center"
justifyContent="center"
>
{chainName && (
{currentChainName && (
<GridItem marginBottom={'20px'}>
<ChainCard
prettyName={chain?.label || chainName}
prettyName={chain?.label || currentChainName}
icon={chain?.icon}
/>
</GridItem>
Expand Down
4 changes: 2 additions & 2 deletions 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.5",
"@cosmjs/cosmwasm-stargate": "0.29.2",
"@cosmjs/stargate": "0.29.2",
"@cosmos-kit/react": "0.18.4",
"@cosmos-kit/react": "0.18.6",
"@cosmos-kit/types": "^0.11.0",
"@emotion/react": "11.10.4",
"@emotion/styled": "11.10.4",
Expand All @@ -41,4 +41,4 @@
"eslint-config-next": "12.2.5",
"typescript": "4.7.4"
}
}
}
4 changes: 2 additions & 2 deletions examples/contracts/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function CreateCosmosApp({ Component, pageProps }: AppProps) {
return (
<ChakraProvider theme={defaultTheme}>
<WalletProvider
chains={chains.filter(chain => chain.chain_name === chainName)}
assetLists={assets.filter(asset => asset.chain_name === chainName)}
chains={chains}
assetLists={assets}
wallets={wallets}
signerOptions={signerOptions}
>
Expand Down
57 changes: 21 additions & 36 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, useMemo } from 'react';
import { MouseEventHandler, useEffect } from 'react';
import { FiAlertTriangle } from 'react-icons/fi';
import {
Astronaut,
Expand All @@ -27,9 +27,8 @@ import {
WalletConnectComponent,
ChainCard
} from '../components';
import { getWalletPrettyName } from '@cosmos-kit/config';
import { assets as chainAssets } from 'chain-registry';
import { ChainRecord } from '@cosmos-kit/core';
import { chainName } from '../config';


export const WalletSection = () => {
const walletManager = useWallet();
Expand All @@ -41,32 +40,22 @@ export const WalletSection = () => {
address,
message,
currentChainName,
currentWalletName,
chains
currentWallet,
currentChainRecord,
getChainLogo,
setCurrentChain
} = walletManager;

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

const chain = useMemo(
() => {
const getChain = (chainRecord: ChainRecord) => {
const assets = chainAssets.find(
(_chain) => _chain.chain_name === chainRecord.name
)?.assets;
return {
chainName: chainRecord.name,
label: chainRecord.chain.pretty_name,
value: chainRecord.name,
icon: assets
? assets[0]?.logo_URIs?.svg || assets[0]?.logo_URIs?.png
: undefined,
disabled: false
};
}
return getChain(chains[0]);
},
[chains]
);
const chain = {
chainName: currentChainName,
label: currentChainRecord?.chain.pretty_name,
value: currentChainName,
icon: getChainLogo(currentChainName)
}

// Events
const onClickConnect: MouseEventHandler = async (e) => {
Expand Down Expand Up @@ -104,17 +93,13 @@ export const WalletSection = () => {
rejected={
<RejectedWarn
icon={<Icon as={FiAlertTriangle} mt={1} />}
wordOfWarning={`${getWalletPrettyName(
currentWalletName
)}: ${message}`}
wordOfWarning={`${currentWallet?.walletInfo.prettyName}: ${message}`}
/>
}
error={
<RejectedWarn
icon={<Icon as={FiAlertTriangle} mt={1} />}
wordOfWarning={`${getWalletPrettyName(
currentWalletName
)}: ${message}`}
wordOfWarning={`${currentWallet?.walletInfo.prettyName}: ${message}`}
/>
}
/>
Expand All @@ -123,7 +108,7 @@ export const WalletSection = () => {
const userInfo = (
<ConnectedUserInfo username={username} icon={<Astronaut />} />
);
const addressBtn = chainName && (
const addressBtn = currentChainName && (
<CopyAddressBtn
walletStatus={walletStatus}
connected={<ConnectedShowAddress address={address} isLoading={false} />}
Expand All @@ -140,10 +125,10 @@ export const WalletSection = () => {
alignItems="center"
justifyContent="center"
>
{chainName && (
{currentChainName && (
<GridItem marginBottom={'20px'}>
<ChainCard
prettyName={chain?.label || chainName}
prettyName={chain?.label || currentChainName}
icon={chain?.icon}
/>
</GridItem>
Expand Down
4 changes: 2 additions & 2 deletions examples/juno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@cosmjs/stargate": "0.29.2",
"@cosmos-kit/core": "0.19.3",
"@cosmos-kit/keplr": "0.19.3",
"@cosmos-kit/react": "0.18.4",
"@cosmos-kit/react": "0.18.6",
"@emotion/react": "11.10.4",
"@emotion/styled": "11.10.4",
"@juno-network/assets": "0.13.0",
Expand All @@ -37,4 +37,4 @@
"eslint-config-next": "12.2.5",
"typescript": "4.7.4"
}
}
}
4 changes: 2 additions & 2 deletions examples/juno/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function CreateCosmosApp({ Component, pageProps }: AppProps) {
return (
<ChakraProvider theme={defaultTheme}>
<WalletProvider
chains={chains.filter(chain => chain.chain_name === chainName)}
assetLists={assets.filter(asset => asset.chain_name === chainName)}
chains={chains}
assetLists={assets}
wallets={wallets}
signerOptions={signerOptions}
>
Expand Down
57 changes: 21 additions & 36 deletions examples/osmosis-cosmwasm/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, useMemo } from 'react';
import { MouseEventHandler, useEffect } from 'react';
import { FiAlertTriangle } from 'react-icons/fi';
import {
Astronaut,
Expand All @@ -27,9 +27,8 @@ import {
WalletConnectComponent,
ChainCard
} from '../components';
import { getWalletPrettyName } from '@cosmos-kit/config';
import { assets as chainAssets } from 'chain-registry';
import { ChainRecord } from '@cosmos-kit/core';
import { chainName } from '../config';


export const WalletSection = () => {
const walletManager = useWallet();
Expand All @@ -41,32 +40,22 @@ export const WalletSection = () => {
address,
message,
currentChainName,
currentWalletName,
chains
currentWallet,
currentChainRecord,
getChainLogo,
setCurrentChain
} = walletManager;

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

const chain = useMemo(
() => {
const getChain = (chainRecord: ChainRecord) => {
const assets = chainAssets.find(
(_chain) => _chain.chain_name === chainRecord.name
)?.assets;
return {
chainName: chainRecord.name,
label: chainRecord.chain.pretty_name,
value: chainRecord.name,
icon: assets
? assets[0]?.logo_URIs?.svg || assets[0]?.logo_URIs?.png
: undefined,
disabled: false
};
}
return getChain(chains[0]);
},
[chains]
);
const chain = {
chainName: currentChainName,
label: currentChainRecord?.chain.pretty_name,
value: currentChainName,
icon: getChainLogo(currentChainName)
}

// Events
const onClickConnect: MouseEventHandler = async (e) => {
Expand Down Expand Up @@ -104,17 +93,13 @@ export const WalletSection = () => {
rejected={
<RejectedWarn
icon={<Icon as={FiAlertTriangle} mt={1} />}
wordOfWarning={`${getWalletPrettyName(
currentWalletName
)}: ${message}`}
wordOfWarning={`${currentWallet?.walletInfo.prettyName}: ${message}`}
/>
}
error={
<RejectedWarn
icon={<Icon as={FiAlertTriangle} mt={1} />}
wordOfWarning={`${getWalletPrettyName(
currentWalletName
)}: ${message}`}
wordOfWarning={`${currentWallet?.walletInfo.prettyName}: ${message}`}
/>
}
/>
Expand All @@ -123,7 +108,7 @@ export const WalletSection = () => {
const userInfo = (
<ConnectedUserInfo username={username} icon={<Astronaut />} />
);
const addressBtn = chainName && (
const addressBtn = currentChainName && (
<CopyAddressBtn
walletStatus={walletStatus}
connected={<ConnectedShowAddress address={address} isLoading={false} />}
Expand All @@ -140,10 +125,10 @@ export const WalletSection = () => {
alignItems="center"
justifyContent="center"
>
{chainName && (
{currentChainName && (
<GridItem marginBottom={'20px'}>
<ChainCard
prettyName={chain?.label || chainName}
prettyName={chain?.label || currentChainName}
icon={chain?.icon}
/>
</GridItem>
Expand Down
Loading