Skip to content

Commit

Permalink
feat: adding impactsX as wallet option
Browse files Browse the repository at this point in the history
  • Loading branch information
Pieter-Ixo committed Aug 18, 2023
1 parent ca7df3f commit 3fe3fcc
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 8 deletions.
6 changes: 5 additions & 1 deletion components/ChainSelector/ChainSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ const ChainSelector = ({}: ChainSelectorProps) => {
width={32}
/>
)}
<p className={styles.chainName}>{chainOption.chainName}</p>
<p className={styles.chainName}>
{chainOption.chainNetwork === 'mainnet'
? chainOption.chainName
: `${chainOption.chainName} (${chainOption.chainId})`}
</p>
</div>
{chainInfo?.chainId === chainOption.chainId && chain.chainLoading && <Loader size={30} />}
</Card>
Expand Down
9 changes: 9 additions & 0 deletions components/Wallets/Wallets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 (
Expand All @@ -42,6 +44,13 @@ const Wallets = ({ onSelected, className, ...other }: WalletsProps) => {
onClick={() => onSelected(WALLET_TYPE.opera)}
/>
)}
{!!impactsXWallet && (
<WalletCard
name={WALLETS.impactsX.name}
img={WALLETS.impactsX.img}
onClick={() => onSelected(WALLET_TYPE.impactsX)}
/>
)}
{!!walletConnect && (
<WalletCard
name={WALLETS.walletConnect.name}
Expand Down
5 changes: 5 additions & 0 deletions constants/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export const WALLETS = {
img: '/images/wallets/wallet-connect.png',
type: WALLET_TYPE.walletConnect,
},
[WALLET_TYPE.impactsX]: {
name: 'ImpactsX',
img: '/images/wallets/impacts-x.png',
type: WALLET_TYPE.impactsX,
},
};

export const WalletConnectProjectId = process.env.NEXT_PUBLIC_WC_PROJECT_ID;
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "jambo-client",
"version": "0.0.1",
"version": "0.1.0",
"private": true,
"author": "ixo",
"license": "MIT",
"scripts": {
"dev": "next dev -p 3002",
"dev": "next dev -p 3000",
"build": "next build",
"start": "next start",
"lint": "next lint",
Expand All @@ -23,7 +23,7 @@
"@dnd-kit/utilities": "3.2.0",
"@ixo/cosmos-chain-resolver": "0.0.2",
"@ixo/impactxclient-sdk": "1.1.3",
"@ixo/jambo-wallet-sdk": "0.0.3",
"@ixo/jambo-wallet-sdk": "0.1.0",
"@keplr-wallet/cosmos": "0.11.11",
"@keplr-wallet/types": "0.11.10",
"@keplr-wallet/wc-client": "0.11.11",
Expand Down
Binary file added public/images/wallets/impacts-x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions types/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum WALLET_TYPE {
opera = 'opera',
keplr = 'keplr',
walletConnect = 'walletConnect',
impactsX = 'impactsX',
}

export type WALLET = {
Expand Down
66 changes: 66 additions & 0 deletions utils/impactsX.ts
Original file line number Diff line number Diff line change
@@ -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<USER | undefined> => {
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<any> => {
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<string | null> => {
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;
}
};
5 changes: 5 additions & 0 deletions utils/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3fe3fcc

Please sign in to comment.