Skip to content

Commit c3c837a

Browse files
samsiegartturadg
andauthored
feat: onboard IST with elements button (#98)
* feat: query smart wallet auto-provision fee * fix: remove extra purse updates and swingset query * feat: onboard IST with elements button * build: patch xsnap to separate from yarn project works around Agoric/agoric-sdk#9261 * test(rpc): use legacy endo to fix test * build: add prepack script * build: fix some types * chore: add comment for IST icon --------- Co-authored-by: Turadg Aleahmad <[email protected]>
1 parent 53782cd commit c3c837a

File tree

13 files changed

+6925
-5164
lines changed

13 files changed

+6925
-5164
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
diff --git a/package.json b/package.json
2+
index 25ddb12bf728223569f4e53ed8cca20e51813725..876d249fa2584d748f6da234d5104c42090b5f34 100644
3+
--- a/package.json
4+
+++ b/package.json
5+
@@ -12,11 +12,11 @@
6+
},
7+
"scripts": {
8+
"repl": "node src/xsrepl.js",
9+
- "build:bin": "if test -d ./test; then node src/build.js; else yarn build:from-env; fi",
10+
+ "build:bin": "if test -d ./test; then node src/build.js; else npm run build:from-env; fi",
11+
"build:env": "test -d ./test && node src/build.js --show-env > build.env",
12+
"build:from-env": "{ cat build.env; echo node src/build.js; } | xargs env",
13+
- "build": "yarn build:bin && yarn build:env",
14+
- "postinstall": "yarn build:from-env",
15+
+ "build": "npm run build:bin && npm run build:env",
16+
+ "postinstall": "npm run build:from-env",
17+
"clean": "rm -rf xsnap-native/xsnap/build",
18+
"lint": "run-s --continue-on-error lint:*",
19+
"lint:js": "eslint 'src/**/*.js' 'test/**/*.js' api.js",

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"type": "module",
1111
"packageManager": "[email protected]",
1212
"scripts": {
13+
"prepack": "yarn workspaces foreach --all --topological run prepack",
1314
"docs": "typedoc --excludeInternal",
1415
"format": "yarn prettier --write packages",
1516
"lint": "yarn workspaces foreach --all run lint",
@@ -45,7 +46,9 @@
4546
"typescript": "~5.3.3"
4647
},
4748
"resolutions": {
48-
"@agoric/swingset-liveslots": "0.10.3-dev-8c14632.0"
49+
"@agoric/swingset-liveslots": "0.10.3-dev-8c14632.0",
50+
"@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",
51+
"@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"
4952
},
5053
"ava": {
5154
"files": [

packages/react-components/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
"@cosmos-kit/core": "2.8.9",
3131
"@cosmos-kit/react": "2.10.10",
3232
"@interchain-ui/react": "1.21.18",
33+
"@leapwallet/elements": "0.12.1",
3334
"chain-registry": "1.28.0",
3435
"react": "18.2.0",
3536
"react-dom": "18.2.0"
3637
},
3738
"devDependencies": {
3839
"@babel/core": "7.22.10",
40+
"@chain-registry/types": "^0.25.7",
3941
"@headlessui/react": "^1.7.18",
4042
"@testing-library/react": "14.0.0",
4143
"@types/node": "20.4.9",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { type AssetSelector, LiquidityModal, Tabs } from '@leapwallet/elements';
2+
import { useElementsWalletClient } from '../utils';
3+
import { useAgoric } from '../hooks';
4+
import { Ist } from '../icons/Ist';
5+
import { Button } from '@interchain-ui/react';
6+
7+
import '@leapwallet/elements/styles.css';
8+
9+
const agoricChainId = 'agoric-3';
10+
const istSelector: AssetSelector = ['symbol', 'IST'];
11+
const bldSelector: AssetSelector = ['symbol', 'BLD'];
12+
13+
export const OnboardIstModal = () => {
14+
const { address } = useAgoric();
15+
const elementsWalletClient = useElementsWalletClient();
16+
17+
const renderLiquidityButton = ({ onClick }: { onClick: () => void }) => {
18+
return (
19+
<Button onClick={onClick} leftIcon="walletFilled">
20+
Deposit IST
21+
</Button>
22+
);
23+
};
24+
25+
return (
26+
<LiquidityModal
27+
renderLiquidityButton={renderLiquidityButton}
28+
theme="light"
29+
walletClientConfig={{
30+
userAddress: address,
31+
walletClient: elementsWalletClient,
32+
connectWallet: (chainId?: string) => {
33+
return elementsWalletClient.enable(chainId ?? []);
34+
},
35+
}}
36+
defaultActiveTab={Tabs.SWAP}
37+
config={{
38+
icon: Ist,
39+
title: 'Deposit IST',
40+
subtitle: '',
41+
tabsConfig: {
42+
[Tabs.BRIDGE_USDC]: {
43+
enabled: false,
44+
},
45+
[Tabs.FIAT_ON_RAMP]: {
46+
enabled: false,
47+
},
48+
[Tabs.CROSS_CHAIN_SWAPS]: {
49+
enabled: true,
50+
defaults: {
51+
destinationChainId: agoricChainId,
52+
destinationAssetSelector: istSelector,
53+
},
54+
},
55+
[Tabs.SWAP]: {
56+
enabled: true,
57+
defaults: {
58+
sourceChainId: agoricChainId,
59+
sourceAssetSelector: bldSelector,
60+
destinationChainId: agoricChainId,
61+
destinationAssetSelector: istSelector,
62+
},
63+
},
64+
[Tabs.TRANSFER]: {
65+
enabled: true,
66+
defaults: {
67+
destinationChainId: agoricChainId,
68+
sourceChainId: agoricChainId,
69+
sourceAssetSelector: istSelector,
70+
},
71+
},
72+
},
73+
}}
74+
/>
75+
);
76+
};

packages/react-components/src/lib/components/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './ConnectWalletButton';
22
export * from './NodeSelectorModal';
33
export * from './AmountInput';
44
export * from './NetworkDropdown';
5+
export * from './OnboardIstModal';

packages/react-components/src/lib/config/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assets, chains } from 'chain-registry';
2-
import type { Chain, AssetList } from '@chain-registry/types';
2+
import type { AssetList, Chain } from '@chain-registry/types';
33
import type { Endpoints } from '@cosmos-kit/core';
44

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

packages/react-components/src/lib/icons/Ist.ts

+3
Large diffs are not rendered by default.

packages/react-components/src/lib/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './components';
33
export * from './config';
44
export * from './context';
55
export * from './hooks';
6+
export * from './utils';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './leapElementsClient';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import type { WalletClient } from '@leapwallet/elements';
2+
import { useWalletClient } from '@cosmos-kit/react';
3+
import { useMemo } from 'react';
4+
5+
export const useElementsWalletClient = (): WalletClient => {
6+
const { client } = useWalletClient();
7+
8+
// @ts-expect-error Mismatch between `Long` type in `signDoc`
9+
const walletClient: WalletClient = useMemo(() => {
10+
return {
11+
enable: (chainIds: string | string[]) => {
12+
return client!.enable!(chainIds);
13+
},
14+
getAccount: async (chainId: string) => {
15+
await client!.enable!(chainId);
16+
const result = await client!.getAccount!(chainId);
17+
return {
18+
bech32Address: result.address,
19+
pubKey: result.pubkey,
20+
isNanoLedger: !!result.isNanoLedger,
21+
};
22+
},
23+
getSigner: async (chainId: string) => {
24+
const signer = client!.getOfflineSignerDirect!(chainId);
25+
const aminoSigner = client!.getOfflineSignerAmino!(chainId);
26+
27+
return {
28+
signDirect: async (address, signDoc) => {
29+
// @ts-expect-error Mismatch between `Long` type in `signDoc`
30+
const result = await signer.signDirect(address, signDoc);
31+
return {
32+
signature: new Uint8Array(
33+
Buffer.from(result.signature.signature, 'base64'),
34+
),
35+
signed: result.signed,
36+
};
37+
},
38+
signAmino: async (address, signDoc) => {
39+
const result = await aminoSigner.signAmino(address, signDoc);
40+
return {
41+
signature: new Uint8Array(
42+
Buffer.from(result.signature.signature, 'base64'),
43+
),
44+
signed: result.signed,
45+
};
46+
},
47+
};
48+
},
49+
};
50+
}, [client]);
51+
52+
return walletClient;
53+
};

packages/rpc/test/marshal.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import '@endo/init'; // UNTIL https://github.com/endojs/endo/issues/1686
1+
import '@endo/init/legacy.js'; // UNTIL https://github.com/endojs/endo/issues/1686
22
import { expect, test } from 'vitest';
33
import { makeClientMarshaller } from '../src/marshal.js';
44

packages/web-components/src/wallet-connection/watchWallet.ts

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ type VBankAssets = [
3131
{ brand: Brand; issuerName: string; displayInfo: unknown },
3232
][];
3333

34-
/** @typedef {import('@agoric/ertp/src/types.js').Amount<'nat'>['value']} NatValue */
35-
3634
const POLL_INTERVAL_MS = 6000;
3735
const RETRY_INTERVAL_MS = 200;
3836
const MAX_ATTEMPTS_TO_WATCH_BANK = 2;

0 commit comments

Comments
 (0)