-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from 7 commits
6b4c3ae
f9c1cc3
7df695e
65132f5
464f61d
1871176
41108a0
825769a
d361d5f
a79ebb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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", |
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": [ | ||
|
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, | ||
}, | ||
}, | ||
}, | ||
}} | ||
/> | ||
); | ||
}; |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './leapElementsClient'; |
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` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
So seems like the |
||
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; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a this and the one above should be removed. Line 19 actually imports the type There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
There was a problem hiding this comment.
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';
There was a problem hiding this comment.
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 👍