From 3fe3fcc147cd89a80517fe439ea2566b474f954c Mon Sep 17 00:00:00 2001 From: Pieter Pretorius Date: Fri, 18 Aug 2023 12:03:37 +0200 Subject: [PATCH] feat: adding impactsX as wallet option --- components/ChainSelector/ChainSelector.tsx | 6 +- components/Wallets/Wallets.tsx | 9 +++ constants/wallet.ts | 5 ++ package.json | 6 +- public/images/wallets/impacts-x.png | Bin 0 -> 8941 bytes types/wallet.ts | 1 + utils/impactsX.ts | 66 +++++++++++++++++++++ utils/wallets.ts | 5 ++ yarn.lock | 8 +-- 9 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 public/images/wallets/impacts-x.png create mode 100644 utils/impactsX.ts 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 && ( s{-~-noJ`H|F6I z;Q{~vJSG^l72|qy_uyb-oSTO1qyPZkk3l#aA1k~+$kUtZLOM?b`2>0rLBs%(3jh!> zoR>=SmO8dSd}l?7#zOhvEmp=)3)A{>(J_H+0;#HfU*4!(i5pKufd$>mf2_YJ|7f~l zbK5lD-pZ_HS{xBY$Y&^PrB zIi3rM@df{LJL0PO8WDk^>q^y*-{%Y-AK+UZyxkoT*LCiC*lmHX2#*Pk_ex`^(X`%a z3!>qfB$4-{tKqHFs_Q>|SE8*~*CAscV|%C9=I36tT)=g{)@v7Q+itIaQU>(4UiIGC zs9it0`8ma*B3X0RhdS%5G<|s8_i|5R44%~Daw$S`IS_XwqTon)V?~qSk)~7AAs)3e zcReVzzGY23iHEk~x+~8&$C?5kgnurUh{i{4c)p#+HgU7YvfpPvyO!bMDPSmVk_bL! z$E6@^qVO>{cgXwIYeI{{w7qvnX}Ca4JkDDoFVQ-fC-!b1js~e57)UOMc~A6S6SbSG zi#$@BoF250H#o{RraB&b)947X@Acgbe4~VFhjv>@Ii!jsPdKThVp*}c>=9?Bc>DD; ze#3!D4*r|y`O9lbFVAI8QTn!ypP;s96nt^-lrYfD6SQmxwBMdVX)Cd?RGe-4V<-x40T&6RiQRd50wN?Lh1!tVFtT$G~s4wuHQ2|>z_46v(EO+9+y^t;h4L?!pN zu%U#ApaMi}@Ue{!uf#^gh2%H))CTQ6DqbBiH7E0Matn^wmB6Ux4?6qSTWgn-9;_?t zv-CeLE+$3xqimIeNK#cDY-zxZZVciD2JT>vkJPO8`5*>eTQn&$6-xAa{%z#bLWEvl?lwZB#zqr2~d z>C>saTN~b&uR_`mKUqjv9j@w}%l#}*5p6l@8eex{^`b?t#vCqaHb{BUbX|M!=sDUu z)#PBaCGD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ts @@ -16,6 +16,7 @@ export enum WALLET_TYPE { opera = 'opera', keplr = 'keplr', walletConnect = 'walletConnect', + impactsX = 'impactsX', } export type WALLET = { diff --git a/utils/impactsX.ts b/utils/impactsX.ts new file mode 100644 index 0000000..e9563e9 --- /dev/null +++ b/utils/impactsX.ts @@ -0,0 +1,66 @@ +import { getImpactsX as getJamboImpactsX } from '@ixo/jambo-wallet-sdk'; +import { ChainInfo } from '@keplr-wallet/types'; + +import * as Toast from '@components/Toast/Toast'; +import { sendTransaction, initStargateClient } from './client'; +import { TRX_FEE_OPTION, TRX_MSG } from 'types/transactions'; +import { USER } from 'types/user'; + +export const getImpactsX = getJamboImpactsX; + +export const initializeImpactsX = async (chainInfo: ChainInfo): Promise => { + 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"