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

feat: onboard IST with elements button #98

Merged
merged 10 commits into from
Apr 24, 2024
19 changes: 19 additions & 0 deletions .yarn/patches/@agoric-xsnap-npm-0.14.3-u14.0-768ce73dba.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/package.json b/package.json
index 25ddb12bf728223569f4e53ed8cca20e51813725..876d249fa2584d748f6da234d5104c42090b5f34 100644
--- a/package.json
+++ b/package.json
@@ -12,11 +12,11 @@
},
"scripts": {
"repl": "node src/xsrepl.js",
- "build:bin": "if test -d ./test; then node src/build.js; else yarn build:from-env; fi",
+ "build:bin": "if test -d ./test; then node src/build.js; else npm run build:from-env; fi",
"build:env": "test -d ./test && node src/build.js --show-env > build.env",
"build:from-env": "{ cat build.env; echo node src/build.js; } | xargs env",
- "build": "yarn build:bin && yarn build:env",
- "postinstall": "yarn build:from-env",
+ "build": "npm run build:bin && npm run build:env",
+ "postinstall": "npm run build:from-env",
"clean": "rm -rf xsnap-native/xsnap/build",
"lint": "run-s --continue-on-error lint:*",
"lint:js": "eslint 'src/**/*.js' 'test/**/*.js' api.js",
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"type": "module",
"packageManager": "[email protected]",
"scripts": {
"prepack": "yarn workspaces foreach --all --topological run prepack",
"docs": "typedoc --excludeInternal",
"format": "yarn prettier --write packages",
"lint": "yarn workspaces foreach --all run lint",
Expand Down Expand Up @@ -45,7 +46,9 @@
"typescript": "~5.3.3"
},
"resolutions": {
"@agoric/swingset-liveslots": "0.10.3-dev-8c14632.0"
"@agoric/swingset-liveslots": "0.10.3-dev-8c14632.0",
"@agoric/xsnap@npm:^0.14.3-u14.0": "patch:@agoric/xsnap@npm%3A0.14.3-u14.0#~/.yarn/patches/@agoric-xsnap-npm-0.14.3-u14.0-768ce73dba.patch",
"@agoric/xsnap@npm:^0.14.2": "patch:@agoric/xsnap@npm%3A0.14.3-u14.0#~/.yarn/patches/@agoric-xsnap-npm-0.14.3-u14.0-768ce73dba.patch"
},
"ava": {
"files": [
Expand Down
1 change: 1 addition & 0 deletions packages/react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@cosmos-kit/core": "2.8.9",
"@cosmos-kit/react": "2.10.10",
"@interchain-ui/react": "1.21.18",
"@leapwallet/elements": "0.12.1",
"chain-registry": "1.28.0",
"react": "18.2.0",
"react-dom": "18.2.0"
Expand Down
76 changes: 76 additions & 0 deletions packages/react-components/src/lib/components/OnboardIstModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { type AssetSelector, LiquidityModal, Tabs } from '@leapwallet/elements';
import { useElementsWalletClient } from '../utils';
import { useAgoric } from '../hooks';
import { Ist } from '../icons/Ist';
import { Button } from '@interchain-ui/react';

import '@leapwallet/elements/styles.css';

const agoricChainId = 'agoric-3';
const istSelector: AssetSelector = ['symbol', 'IST'];
const bldSelector: AssetSelector = ['symbol', 'BLD'];

export const OnboardIstModal = () => {
const { address } = useAgoric();
const elementsWalletClient = useElementsWalletClient();

const renderLiquidityButton = ({ onClick }: { onClick: () => void }) => {
return (
<Button onClick={onClick} leftIcon="walletFilled">
Deposit IST
</Button>
);
};

return (
<LiquidityModal
renderLiquidityButton={renderLiquidityButton}
theme="light"
walletClientConfig={{
userAddress: address,
walletClient: elementsWalletClient,
connectWallet: (chainId?: string) => {
return elementsWalletClient.enable(chainId ?? []);
},
}}
defaultActiveTab={Tabs.SWAP}
config={{
icon: Ist,
title: 'Deposit IST',
subtitle: '',
tabsConfig: {
[Tabs.BRIDGE_USDC]: {
enabled: false,
},
[Tabs.FIAT_ON_RAMP]: {
enabled: false,
},
[Tabs.CROSS_CHAIN_SWAPS]: {
enabled: true,
defaults: {
destinationChainId: agoricChainId,
destinationAssetSelector: istSelector,
},
},
[Tabs.SWAP]: {
enabled: true,
defaults: {
sourceChainId: agoricChainId,
sourceAssetSelector: bldSelector,
destinationChainId: agoricChainId,
destinationAssetSelector: istSelector,
},
},
[Tabs.TRANSFER]: {
enabled: true,
defaults: {
destinationChainId: agoricChainId,
sourceChainId: agoricChainId,
sourceAssetSelector: istSelector,
},
},
},
}}
/>
);
};
1 change: 1 addition & 0 deletions packages/react-components/src/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './ConnectWalletButton';
export * from './NodeSelectorModal';
export * from './AmountInput';
export * from './NetworkDropdown';
export * from './OnboardIstModal';
4 changes: 3 additions & 1 deletion packages/react-components/src/lib/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { assets, chains } from 'chain-registry';
import type { Chain, AssetList } from '@chain-registry/types';
import type { Endpoints } from '@cosmos-kit/core';

type Chain = (typeof chains)[number];
type AssetList = (typeof assets)[number];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { AssetList, Chain } from '@chain-registry/types';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was seeing some type mismatch and resorted to this, but tried it again and it seems to build 👍


export type ChainConfig = { chains: Chain[]; assetLists: AssetList[] };

export const prettyTestChainName = (name: string) =>
Expand Down
2 changes: 2 additions & 0 deletions packages/react-components/src/lib/icons/Ist.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/react-components/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './components';
export * from './config';
export * from './context';
export * from './hooks';
export * from './utils';
1 change: 1 addition & 0 deletions packages/react-components/src/lib/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './leapElementsClient';
53 changes: 53 additions & 0 deletions packages/react-components/src/lib/utils/leapElementsClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { WalletClient } from '@leapwallet/elements';
import { useWalletClient } from '@cosmos-kit/react';
import { useMemo } from 'react';

export const useElementsWalletClient = (): WalletClient => {
const { client } = useWalletClient();

// @ts-expect-error Mismatch between `Long` type in `signDoc`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't that mismatch handled by line 29? this seems like it's about something else. see if you can ignore a smaller scope or use casting to resolve

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is without the expect-errors, I needed to put them in both places:

$ yarn build
src/lib/utils/leapElementsClient.ts:8:9 - error TS2322: Type '{ enable: (chainIds: string | string[]) => Promise<void>; getAccount: (chainId: string) => Promise<{ bech32Address: string; pubKey: Uint8Array; isNanoLedger: boolean; }>; getSigner: (chainId: string) => Promise<...>; }' is not assignable to type 'WalletClient'.
  The types returned by 'getSigner(...)' are incompatible between these types.
    Type 'Promise<{ signDirect: (address: string, signDoc: SignDoc) => Promise<{ signature: Uint8Array; signed: SignDoc; }>; signAmino: (address: string, signDoc: StdSignDoc) => Promise<...>; }>' is not assignable to type 'Promise<Signer>'.
      Type '{ signDirect: (address: string, signDoc: SignDoc) => Promise<{ signature: Uint8Array; signed: SignDoc; }>; signAmino: (address: string, signDoc: StdSignDoc) => Promise<...>; }' is not assignable to type 'Signer'.
        The types returned by 'signDirect(...)' are incompatible between these types.
          Type 'Promise<{ signature: Uint8Array; signed: SignDoc; }>' is not assignable to type 'Promise<SignDirectResponse | TxRaw>'.
            Type '{ signature: Uint8Array; signed: SignDoc; }' is not assignable to type 'SignDirectResponse | TxRaw'.
              Type '{ signature: Uint8Array; signed: SignDoc; }' is not assignable to type 'SignDirectResponse'.
                The types of 'signed.accountNumber' are incompatible between these types.
                  Type 'bigint' is not assignable to type 'Long'.

8   const walletClient: WalletClient = useMemo(() => {
          ~~~~~~~~~~~~

src/lib/utils/leapElementsClient.ts:28:61 - error TS2345: Argument of type 'import("/home/samsiegart/ui-kit/node_modules/@leapwallet/elements-core/node_modules/cosmjs-types/cosmos/tx/v1beta1/tx").SignDoc' is not assignable to parameter of type 'import("/home/samsiegart/ui-kit/node_modules/cosmjs-types/cosmos/tx/v1beta1/tx").SignDoc'.
  Types of property 'accountNumber' are incompatible.
    Type 'Long' is not assignable to type 'bigint'.

28             const result = await signer.signDirect(address, signDoc);
                                                               ~~~~~~~


Found 2 errors in the same file, starting at: src/lib/utils/leapElementsClient.ts:8

So seems like the cosmjs-types in leap and cosmos-kit differ. I'm not sure how to cast in this scenario, but the errors seem inconsequential.

const walletClient: WalletClient = useMemo(() => {
return {
enable: (chainIds: string | string[]) => {
return client!.enable!(chainIds);
},
getAccount: async (chainId: string) => {
await client!.enable!(chainId);
const result = await client!.getAccount!(chainId);
return {
bech32Address: result.address,
pubKey: result.pubkey,
isNanoLedger: !!result.isNanoLedger,
};
},
getSigner: async (chainId: string) => {
const signer = client!.getOfflineSignerDirect!(chainId);
const aminoSigner = client!.getOfflineSignerAmino!(chainId);

return {
signDirect: async (address, signDoc) => {
// @ts-expect-error Mismatch between `Long` type in `signDoc`
const result = await signer.signDirect(address, signDoc);
return {
signature: new Uint8Array(
Buffer.from(result.signature.signature, 'base64'),
),
signed: result.signed,
};
},
signAmino: async (address, signDoc) => {
const result = await aminoSigner.signAmino(address, signDoc);
return {
signature: new Uint8Array(
Buffer.from(result.signature.signature, 'base64'),
),
signed: result.signed,
};
},
};
},
};
}, [client]);

return walletClient;
};
2 changes: 1 addition & 1 deletion packages/rpc/test/marshal.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@endo/init'; // UNTIL https://github.com/endojs/endo/issues/1686
import '@endo/init/legacy.js'; // UNTIL https://github.com/endojs/endo/issues/1686
import { expect, test } from 'vitest';
import { makeClientMarshaller } from '../src/marshal.js';

Expand Down
2 changes: 2 additions & 0 deletions packages/web-components/src/wallet-connection/watchWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type VBankAssets = [

/** @typedef {import('@agoric/ertp/src/types.js').Amount<'nat'>['value']} NatValue */

/** @typedef {import('@agoric/ertp/src/types.js').Amount<'nat'>['value']} NatValue */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a .ts file so the jsdoc tyepdefs do nothing.

this and the one above should be removed. Line 19 actually imports the type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yea this seems to be a merge artifact, removed.


const POLL_INTERVAL_MS = 6000;
const RETRY_INTERVAL_MS = 200;
const MAX_ATTEMPTS_TO_WATCH_BANK = 2;
Expand Down
Loading
Loading