Skip to content

Commit

Permalink
fix(app): wallet fix (#2055)
Browse files Browse the repository at this point in the history
## Changes

- Added chaininfo for leap & keplr
- Adjusted `cosmosStore.connect` to add chain and handle
error/rejections

#### Docs for wallets in regards to this change.

- [Keplr](https://docs.keplr.app/api/suggest-chain.html)
-
[Leap](https://docs.leapwallet.io/cosmos/for-dapps-connect-to-leap/suggest-chain-add-leap-to-a-non-native-chain)
  • Loading branch information
o-az authored Jun 7, 2024
2 parents b12c744 + cce6062 commit 5bbd717
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 4 deletions.
109 changes: 109 additions & 0 deletions app/src/lib/wallet/cosmos/chain-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import type { ChainInfo as KeplrChainInfo } from "@keplr-wallet/types"
import type { ChainInfo as LeapChainInfo } from "@leapwallet/types"

//This exist according to docs
interface LeapExtendedInfo extends LeapChainInfo {
theme: {
primaryColor: string
gradient: string
}
image: string
}

//todo handle this for main-net
export const keplrChainInfo: KeplrChainInfo = {
chainId: "union-testnet-8",
chainName: "uniontestnet",
rest: "https://api.testnet.bonlulu.uno",
rpc: "https://rpc.testnet.bonlulu.uno",
bip44: {
coinType: 118
},
bech32Config: {
bech32PrefixAccAddr: "union",
bech32PrefixAccPub: "unionpub",
bech32PrefixValAddr: "unionvaloper",
bech32PrefixValPub: "unionvaloperpub",
bech32PrefixConsAddr: "unionvalcons",
bech32PrefixConsPub: "unionvalconspub"
},
currencies: [
{
coinDenom: "UNO",
coinMinimalDenom: "muno",
coinDecimals: 6,
coinGeckoId: "cosmos"
}
],
feeCurrencies: [
{
coinDenom: "UNO",
coinMinimalDenom: "muno",
coinDecimals: 6,
coinGeckoId: "union",
gasPriceStep: {
low: 0.0025,
average: 0.025,
high: 0.04
}
}
],
stakeCurrency: {
coinDenom: "UNO",
coinMinimalDenom: "muno",
coinDecimals: 6,
coinGeckoId: "union"
}
}

//todo handle this for main-net
export const leapChainInfo: LeapExtendedInfo = {
chainId: "union-testnet-8",
chainName: "uniontestnet",
rest: "https://api.testnet.bonlulu.uno",
rpc: "https://rpc.testnet.bonlulu.uno",
bip44: {
coinType: 118
},
bech32Config: {
bech32PrefixAccAddr: "union",
bech32PrefixAccPub: "unionpub",
bech32PrefixValAddr: "unionvaloper",
bech32PrefixValPub: "unionvaloperpub",
bech32PrefixConsAddr: "unionvalcons",
bech32PrefixConsPub: "unionvalconspub"
},
currencies: [
{
coinDenom: "UNO",
coinMinimalDenom: "muno",
coinDecimals: 6,
coinGeckoId: "cosmos"
}
],
feeCurrencies: [
{
coinDenom: "UNO",
coinMinimalDenom: "muno",
coinDecimals: 6,
coinGeckoId: "union"
}
],
gasPriceStep: {
low: 0.0025,
average: 0.025,
high: 0.04
},
stakeCurrency: {
coinDenom: "UNO",
coinMinimalDenom: "muno",
coinDecimals: 6,
coinGeckoId: "union"
},
theme: {
primaryColor: "#fff",
gradient: "linear-gradient(180deg, rgba(255, 255, 255, 0.32) 0%, rgba(255, 255, 255, 0) 100%)"
},
image:
"https://raw.githubusercontent.com/cosmos/chain-registry/master/testnets/uniontestnet/images/union.png"
}
23 changes: 19 additions & 4 deletions app/src/lib/wallet/cosmos/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { get } from "svelte/store"
import { sleep } from "$lib/utilities/index.ts"
import { persisted } from "svelte-persisted-store"
import type { ChainWalletStore } from "$lib/wallet/types"
import { keplrChainInfo, leapChainInfo } from "$lib/wallet/cosmos/chain-info.ts"

export const cosmosWalletsInformation = [
{
Expand Down Expand Up @@ -43,12 +44,27 @@ function createCosmosStore(
connect: async (walletId: string) => {
if (!walletId || (walletId !== "keplr" && walletId !== "leap")) return
update(v => ({ ...v, connectionStatus: "connecting", connectedWallet: walletId }))
if (!window[walletId]) {
const walletApi = window[walletId]
if (!walletApi) {
alert(`Please install ${walletId} wallet`)
return update(v => ({ ...v, connectionStatus: "disconnected" }))
}
await window[walletId]?.enable(["union-testnet-8"])
const account = await window[walletId]?.getKey("union-testnet-8")
const chainInfoMap = {
keplr: keplrChainInfo,
leap: leapChainInfo
}
const chainInfo = chainInfoMap[walletId]
if (!chainInfo) {
alert("Chain information is missing for the selected wallet.")
return update(v => ({ ...v, connectionStatus: "disconnected" }))
}
try {
await walletApi.experimentalSuggestChain(chainInfo)
await walletApi.enable(["union-testnet-8"])
} catch (e) {
return update(v => ({ ...v, connectionStatus: "disconnected" }))
}
const account = await walletApi.getKey("union-testnet-8")
update(v => ({
...v,
connectionStatus: "connected",
Expand All @@ -59,7 +75,6 @@ function createCosmosStore(
},
disconnect: async () => {
const cosmosWalletId = get({ subscribe }).connectedWallet as CosmosWalletId
console.log({ cosmosWalletId })
console.log("[cosmos] cosmosDisconnectClick", get(cosmosStore))
if (cosmosWalletId && cosmosWalletId === "keplr" && window[cosmosWalletId]) {
await window[cosmosWalletId]?.disable("union-testnet-8")
Expand Down
7 changes: 7 additions & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

0xbonlulu
0xc0dejug
0xkaiserkarel
Expand Down Expand Up @@ -1076,8 +1077,14 @@ unionmodule
unionmodulekeeper
unionmoduletypes
unionp
unionpub
unionsimulation
unionstaking
uniontestnet
unionvalcons
unionvalconspub
unionvaloper
unionvaloperpub
unionvisor
unittests
unjail
Expand Down

0 comments on commit 5bbd717

Please sign in to comment.