Skip to content

Instantly share code, notes, and snippets.

@adairrr
Created November 17, 2022 17:56
Show Gist options
  • Save adairrr/8fbf4d9e12922e2a74ce0a511707d1b8 to your computer and use it in GitHub Desktop.
Save adairrr/8fbf4d9e12922e2a74ce0a511707d1b8 to your computer and use it in GitHub Desktop.
import React, { FC, PropsWithChildren } from 'react'
import { assets, chains } from 'chain-registry'
import { wallets as keplrWallets } from '@cosmos-kit/keplr'
import { wallets as stationWallets } from '@cosmos-kit/cosmostation'
import { GasPrice } from '@cosmjs/stargate'
import { SigningCosmWasmClientOptions } from '@cosmjs/cosmwasm-stargate'
import { WalletProvider } from 'contexts/WalletContext'
import { DefaultModal, WalletProvider as CosmosKitWalletProvider } from '@cosmos-kit/react'
import { MainWalletBase, SignerOptions } from '@cosmos-kit/core'
import { Chain as ChainRegistryChain } from '@chain-registry/types'
const LOCAL_JUNO_CHAIN: ChainRegistryChain = {
$schema: '../../chain.schema.json',
chain_name: 'localjuno',
status: 'live',
network_type: 'testnet',
pretty_name: 'LocalJuno',
chain_id: 'testing',
bech32_prefix: 'juno',
daemon_name: 'junod',
node_home: '$HOME/.juno',
key_algos: ['secp256k1'],
slip44: 118,
fees: {
fee_tokens: [
{
denom: 'ujunox',
low_gas_price: 0.03,
average_gas_price: 0.04,
high_gas_price: 0.05,
},
],
},
staking: {
staking_tokens: [
{
denom: 'ujunox',
},
],
},
codebase: {
git_repo: 'https://github.com/CosmosContracts/juno',
recommended_version: 'v11.0.0',
compatible_versions: ['v11.0.0'],
cosmos_sdk_version: '0.45',
tendermint_version: '0.34',
cosmwasm_version: '0.27',
cosmwasm_enabled: true,
genesis: {
genesis_url:
'https://raw.githubusercontent.com/CosmosContracts/testnets/main/uni-5/genesis.json',
},
},
peers: {
seeds: [],
persistent_peers: [],
},
apis: {
rpc: [
{
address: 'http://localhost:26657',
},
],
rest: [
{
address: 'http://localhost:1317',
},
],
grpc: [
{
address: 'http://localhost:9090',
},
],
},
explorers: [
{
kind: 'LocalExplorer',
url: 'https://localhost:3010',
tx_page: 'https://localhost:3010/txs/${txHash}',
},
],
}
/**
* Wrapper around the wallet provider and the cosmos kit wallet provider.
* @param children
*/
export const CosmosWalletProvider: FC<PropsWithChildren> = ({ children }) => {
const signerOptions: SignerOptions = {
signingCosmwasm: ({ chain_name }): SigningCosmWasmClientOptions | undefined => {
let gasTokenName: string | undefined
switch (chain_name) {
case 'localjuno':
case 'junotestnet':
gasTokenName = 'ujunox'
break
case 'juno':
gasTokenName = 'ujuno'
break
case 'archway':
gasTokenName = 'uarch'
break
}
// @ts-ignore messed up cosmjs dependencies
return gasTokenName ? { gasPrice: GasPrice.fromString(`0.0025${gasTokenName}`) } : undefined
},
}
const wallets: MainWalletBase[] = [...keplrWallets, ...stationWallets]
// set localjuno preferred endpoints
wallets.map(
(wallet) =>
(wallet.preferredEndpoints = {
localjuno: {
rpc: ['http://localhost:26657'],
rest: ['http://localhost:1317'],
},
...wallet.preferredEndpoints,
})
)
return (
<CosmosKitWalletProvider
walletModal={DefaultModal}
chains={[...chains, LOCAL_JUNO_CHAIN]}
assetLists={assets}
wallets={wallets}
signerOptions={signerOptions}
>
<WalletProvider>{children}</WalletProvider>
</CosmosKitWalletProvider>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment