diff --git a/components/ChainSelector/ChainSelector.tsx b/components/ChainSelector/ChainSelector.tsx index 2275a97..13ce161 100644 --- a/components/ChainSelector/ChainSelector.tsx +++ b/components/ChainSelector/ChainSelector.tsx @@ -80,7 +80,11 @@ const ChainSelector = ({}: ChainSelectorProps) => { width={32} /> )} -

{chainOption.chainName}

+

+ {chainOption.chainNetwork === 'mainnet' + ? chainOption.chainName + : `${chainOption.chainName} (${chainOption.chainId})`} +

{chainInfo?.chainId === chainOption.chainId && chain.chainLoading && } diff --git a/components/Wallets/Wallets.tsx b/components/Wallets/Wallets.tsx index 5a9d5d1..3cffd27 100644 --- a/components/Wallets/Wallets.tsx +++ b/components/Wallets/Wallets.tsx @@ -7,6 +7,7 @@ import ColoredIcon, { ICON_COLOR } from '@components/ColoredIcon/ColoredIcon'; import WalletCard from '@components/CardWallet/CardWallet'; import WalletImg from '@icons/wallet.svg'; import { getWalletConnect } from '@utils/walletConnect'; +import { getImpactsX } from '@utils/impactsX'; import { getOpera } from '@utils/opera'; import { getKeplr } from '@utils/keplr'; import { WALLETS } from '@constants/wallet'; @@ -19,6 +20,7 @@ type WalletsProps = { const Wallets = ({ onSelected, className, ...other }: WalletsProps) => { const keplrWallet = getKeplr(); const operaWallet = getOpera(); + const impactsXWallet = getImpactsX(); const walletConnect = getWalletConnect(); return ( @@ -42,6 +44,13 @@ const Wallets = ({ onSelected, className, ...other }: WalletsProps) => { onClick={() => onSelected(WALLET_TYPE.opera)} /> )} + {!!impactsXWallet && ( + onSelected(WALLET_TYPE.impactsX)} + /> + )} {!!walletConnect && ( => { + const impactsX = getImpactsX(); + if (!impactsX) return; + try { + // await impactsX.experimentalSuggestChain(chainInfo as ChainInfo); + await impactsX.enable(chainInfo.chainId, 'testnet'); + const key = await impactsX.getKey(chainInfo.chainId); + return key + ? { name: key.name, pubKey: key.pubKey, address: key.bech32Address, algo: key.algo, ledgered: true } + : undefined; + } catch (error) { + console.error('Error initializing impactsX:: ' + error); + } +}; + +export const connectImpactsXAccount = async (chainInfo: ChainInfo): Promise => { + const impactsX = getImpactsX(); + if (!impactsX) return [null, null]; + const offlineSigner = impactsX.getOfflineSigner(chainInfo.chainId); + if (!offlineSigner) return [null, null]; + const accounts = await offlineSigner.getAccounts(); + return [accounts, offlineSigner]; +}; + +export const impactsXBroadCastMessage = async ( + msgs: TRX_MSG[], + memo = '', + fee: TRX_FEE_OPTION, + feeDenom: string, + chainInfo: ChainInfo, +): Promise => { + try { + const [accounts, offlineSigner] = await connectImpactsXAccount(chainInfo); + + if (!accounts) throw new Error('No accounts found to broadcast transaction'); + if (!offlineSigner) throw new Error('No offlineSigner found to broadcast transaction'); + + const address = accounts[0].address; + const client = await initStargateClient(chainInfo.rpc, offlineSigner); + const payload = { + msgs, + chain_id: chainInfo.chainId, + fee, + feeDenom, + memo, + }; + const result = await sendTransaction(client, address, payload); + + if (!result) throw new Error('Transaction Failed - ' + JSON.stringify(result)); + + return result.transactionHash; + } catch (e) { + Toast.errorToast(`Transaction Failed ${(e as Error).message}`); + return null; + } +}; diff --git a/utils/wallets.ts b/utils/wallets.ts index bda1a78..10a762c 100644 --- a/utils/wallets.ts +++ b/utils/wallets.ts @@ -8,6 +8,7 @@ import { USER } from 'types/user'; import { initializeWC, WCBroadCastMessage } from './walletConnect'; import { initializeKeplr, keplrBroadCastMessage } from './keplr'; import { initializeOpera, operaBroadCastMessage } from './opera'; +import { initializeImpactsX, impactsXBroadCastMessage } from './impactsX'; import { getFeeDenom, TOKEN_ASSET } from './currency'; import { DELEGATION, UNBONDING_DELEGATION } from 'types/validators'; import { sumArray } from './misc'; @@ -88,6 +89,8 @@ export const initializeWallet = async ( return await initializeKeplr(chain as ChainInfo); case WALLET_TYPE.opera: return await initializeOpera(chain as ChainInfo); + case WALLET_TYPE.impactsX: + return await initializeImpactsX(chain as ChainInfo); case WALLET_TYPE.walletConnect: return await initializeWC(chain as ChainInfo); default: @@ -108,6 +111,8 @@ export const broadCastMessages = async ( switch (wallet.walletType) { case WALLET_TYPE.keplr: return await keplrBroadCastMessage(msgs, memo, fee, feeDenom, chain as ChainInfo); + case WALLET_TYPE.impactsX: + return await impactsXBroadCastMessage(msgs, memo, fee, feeDenom, chain as ChainInfo); case WALLET_TYPE.opera: return await operaBroadCastMessage(msgs, memo, fee, feeDenom, chain as ChainInfo); case WALLET_TYPE.walletConnect: diff --git a/yarn.lock b/yarn.lock index f024062..e695f4c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1748,10 +1748,10 @@ dotenv "16.0.3" protobufjs "6.11.2" -"@ixo/jambo-wallet-sdk@0.0.3": - version "0.0.3" - resolved "https://registry.yarnpkg.com/@ixo/jambo-wallet-sdk/-/jambo-wallet-sdk-0.0.3.tgz#b4cd1d8daf312edcd38af891ea476db7c4e3b0bd" - integrity sha512-rFMMu7o72jvhRvDu2vzul+n3H3v744FrXqdJV8PClsfyS3tdkk4Ndm8JhujpogE6mLnlHEY7mz4pvovTudc5Pg== +"@ixo/jambo-wallet-sdk@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@ixo/jambo-wallet-sdk/-/jambo-wallet-sdk-0.1.0.tgz#33fcbb228566c4f6b5634f9725fe1fb95b3207eb" + integrity sha512-y5xwpDCFZX1YqXoHqJb5XROhhcxXCQMJuFJaYUjPTyWWGVTDL81cMcW6FdunI4acFvxHP4nuWkrbz+0iEB0gNQ== dependencies: "@babel/runtime" "7.19.4" "@cosmjs/amino" "0.30.1"