-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
53782cd
commit c3c837a
Showing
13 changed files
with
6,925 additions
and
5,164 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
.yarn/patches/@agoric-xsnap-npm-0.14.3-u14.0-768ce73dba.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -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": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/react-components/src/lib/components/OnboardIstModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
}, | ||
}} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './leapElementsClient'; |
53 changes: 53 additions & 0 deletions
53
packages/react-components/src/lib/utils/leapElementsClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.