-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Connect using Leap Wallet support
- Loading branch information
Himanshu Singh
authored and
Himanshu Singh
committed
Oct 17, 2023
1 parent
2c97d8f
commit befb534
Showing
32 changed files
with
2,962 additions
and
2,516 deletions.
There are no files selected for viewing
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
25 changes: 13 additions & 12 deletions
25
web/src/_helpers/keplr-utils.ts → web/src/_helpers/wallet-utils.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 |
---|---|---|
@@ -1,43 +1,44 @@ | ||
import { SigningCosmosClient } from '@cosmjs/launchpad'; | ||
import { KeplrWallet } from '../recoil/atoms'; | ||
import { Wallet } from '../recoil/atoms'; | ||
import { getRpcNode } from '../hooks/useRpcNode'; | ||
import { Wallets } from '../hooks/useWallet'; | ||
|
||
const initalState = { | ||
accounts: [], | ||
offlineSigner: undefined, | ||
cosmosClient: undefined, | ||
isSignedIn: false, | ||
file: '_helpers/keplr-utils.ts', | ||
isSignedIn: '', | ||
file: '_helpers/wallet-utils.ts', | ||
}; | ||
|
||
export const getKeplr = async (): Promise<KeplrWallet> => { | ||
export const getWallet = async (): Promise<Wallet> => { | ||
const { chainId, rpcNode } = getRpcNode(); | ||
|
||
if (!window.keplr) { | ||
if (!window.wallet) { | ||
return initalState; | ||
} else { | ||
// Enabling before using the Keplr is recommended. | ||
// Enabling before using the Wallet is recommended. | ||
// This method will ask the user whether to allow access if they haven't visited this website. | ||
// Also, it will request that the user unlock the wallet if the wallet is locked. | ||
await window.keplr.enable(chainId); | ||
await window.wallet.enable(chainId); | ||
|
||
const offlineSigner = window.keplr.getOfflineSigner(chainId); | ||
const offlineSigner = window.wallet.getOfflineSigner(chainId); | ||
|
||
// You can get the address/public keys by `getAccounts` method. | ||
// It can return the array of address/public key. | ||
// But, currently, Keplr extension manages only one address/public key pair. | ||
// But, currently, Leap and Keplr extension manages only one address/public key pair. | ||
// XXX: This line is needed to set the sender address for SigningCosmosClient. | ||
const accounts = await offlineSigner.getAccounts(); | ||
|
||
// Initialize the gaia api with the offline signer that is injected by Keplr extension. | ||
// Initialize the gaia api with the offline signer that is injected by Leap/Keplr extension. | ||
const cosmJS = new SigningCosmosClient(rpcNode, accounts[0].address, offlineSigner); | ||
|
||
return { | ||
accounts: [...accounts], | ||
offlineSigner: offlineSigner, | ||
cosmosClient: cosmJS, | ||
isSignedIn: true, | ||
file: '_helpers/keplr-utils.ts', | ||
isSignedIn: window.wallet.constructor.name === 'Leap' ? Wallets.LEAP : Wallets.KEPLR, | ||
file: '_helpers/wallet-utils.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
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.