From 6130ab9b3e1827713291c209c99c2649934756d1 Mon Sep 17 00:00:00 2001 From: Lukas Date: Fri, 7 Jun 2024 01:32:20 +0200 Subject: [PATCH 1/2] fix(app): wallet fix --- app/src/lib/wallet/cosmos/chain-info.ts | 109 ++++++++++++++++++++++++ app/src/lib/wallet/cosmos/config.ts | 45 +++++++--- 2 files changed, 140 insertions(+), 14 deletions(-) create mode 100644 app/src/lib/wallet/cosmos/chain-info.ts diff --git a/app/src/lib/wallet/cosmos/chain-info.ts b/app/src/lib/wallet/cosmos/chain-info.ts new file mode 100644 index 0000000000..68ac687856 --- /dev/null +++ b/app/src/lib/wallet/cosmos/chain-info.ts @@ -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", +} diff --git a/app/src/lib/wallet/cosmos/config.ts b/app/src/lib/wallet/cosmos/config.ts index ac3a701e04..2c46f0db57 100644 --- a/app/src/lib/wallet/cosmos/config.ts +++ b/app/src/lib/wallet/cosmos/config.ts @@ -1,7 +1,8 @@ -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 {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 = [ { @@ -32,7 +33,7 @@ function createCosmosStore( } ) { console.log("[cosmosStore] previousState", previousState) - const { subscribe, set, update } = persisted("cosmos-store", previousState, { + const {subscribe, set, update} = persisted("cosmos-store", previousState, { syncTabs: true, storage: "session" }) @@ -42,13 +43,28 @@ function createCosmosStore( subscribe, connect: async (walletId: string) => { if (!walletId || (walletId !== "keplr" && walletId !== "leap")) return - update(v => ({ ...v, connectionStatus: "connecting", connectedWallet: walletId })) - if (!window[walletId]) { + update(v => ({...v, connectionStatus: "connecting", connectedWallet: walletId})) + const walletApi = window[walletId]; + if (!walletApi) { alert(`Please install ${walletId} wallet`) - return update(v => ({ ...v, connectionStatus: "disconnected" })) + 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", @@ -58,16 +74,16 @@ function createCosmosStore( await sleep(2_000) }, disconnect: async () => { - const cosmosWalletId = get({ subscribe }).connectedWallet as CosmosWalletId - console.log({ cosmosWalletId }) + 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") - update(v => ({ ...v, connectedWallet: "none", connectionStatus: "disconnected" })) + update(v => ({...v, connectedWallet: "none", connectionStatus: "disconnected"})) } if (cosmosWalletId && cosmosWalletId === "leap" && window[cosmosWalletId]) { await window[cosmosWalletId]?.disconnect("union-testnet-8") - update(v => ({ ...v, connectedWallet: "none", connectionStatus: "disconnected" })) + update(v => ({...v, connectedWallet: "none", connectionStatus: "disconnected"})) } } } @@ -75,3 +91,4 @@ function createCosmosStore( export const cosmosStore = createCosmosStore() // cosmosStore.subscribe(value => localStorage.setItem("cosmos-config", JSON.stringify(value))) + From cce6062d7dabb89d3562489ddb14f9aa9cc50861 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 7 Jun 2024 01:55:35 -0700 Subject: [PATCH 2/2] fix: fmt and spellcheck --- app/src/lib/wallet/cosmos/chain-info.ts | 54 ++++++++++++------------- app/src/lib/wallet/cosmos/config.ts | 38 +++++++++-------- dictionary.txt | 7 ++++ 3 files changed, 52 insertions(+), 47 deletions(-) diff --git a/app/src/lib/wallet/cosmos/chain-info.ts b/app/src/lib/wallet/cosmos/chain-info.ts index 68ac687856..12572a40d5 100644 --- a/app/src/lib/wallet/cosmos/chain-info.ts +++ b/app/src/lib/wallet/cosmos/chain-info.ts @@ -1,13 +1,13 @@ -import type {ChainInfo as KeplrChainInfo} from "@keplr-wallet/types"; -import type {ChainInfo as LeapChainInfo} from "@leapwallet/types"; +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; + primaryColor: string + gradient: string + } + image: string } //todo handle this for main-net @@ -17,7 +17,7 @@ export const keplrChainInfo: KeplrChainInfo = { rest: "https://api.testnet.bonlulu.uno", rpc: "https://rpc.testnet.bonlulu.uno", bip44: { - coinType: 118, + coinType: 118 }, bech32Config: { bech32PrefixAccAddr: "union", @@ -25,15 +25,15 @@ export const keplrChainInfo: KeplrChainInfo = { bech32PrefixValAddr: "unionvaloper", bech32PrefixValPub: "unionvaloperpub", bech32PrefixConsAddr: "unionvalcons", - bech32PrefixConsPub: "unionvalconspub", + bech32PrefixConsPub: "unionvalconspub" }, currencies: [ { coinDenom: "UNO", coinMinimalDenom: "muno", coinDecimals: 6, - coinGeckoId: "cosmos", - }, + coinGeckoId: "cosmos" + } ], feeCurrencies: [ { @@ -44,16 +44,16 @@ export const keplrChainInfo: KeplrChainInfo = { gasPriceStep: { low: 0.0025, average: 0.025, - high: 0.04, - }, - }, + high: 0.04 + } + } ], stakeCurrency: { coinDenom: "UNO", coinMinimalDenom: "muno", coinDecimals: 6, - coinGeckoId: "union", - }, + coinGeckoId: "union" + } } //todo handle this for main-net @@ -63,7 +63,7 @@ export const leapChainInfo: LeapExtendedInfo = { rest: "https://api.testnet.bonlulu.uno", rpc: "https://rpc.testnet.bonlulu.uno", bip44: { - coinType: 118, + coinType: 118 }, bech32Config: { bech32PrefixAccAddr: "union", @@ -71,39 +71,39 @@ export const leapChainInfo: LeapExtendedInfo = { bech32PrefixValAddr: "unionvaloper", bech32PrefixValPub: "unionvaloperpub", bech32PrefixConsAddr: "unionvalcons", - bech32PrefixConsPub: "unionvalconspub", + bech32PrefixConsPub: "unionvalconspub" }, currencies: [ { coinDenom: "UNO", coinMinimalDenom: "muno", coinDecimals: 6, - coinGeckoId: "cosmos", - }, + coinGeckoId: "cosmos" + } ], feeCurrencies: [ { coinDenom: "UNO", coinMinimalDenom: "muno", coinDecimals: 6, - coinGeckoId: "union", - }, + coinGeckoId: "union" + } ], gasPriceStep: { low: 0.0025, average: 0.025, - high: 0.04, + high: 0.04 }, stakeCurrency: { coinDenom: "UNO", coinMinimalDenom: "muno", coinDecimals: 6, - coinGeckoId: "union", + coinGeckoId: "union" }, theme: { - primaryColor: '#fff', - gradient: - 'linear-gradient(180deg, rgba(255, 255, 255, 0.32) 0%, rgba(255, 255, 255, 0) 100%)', + 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", + image: + "https://raw.githubusercontent.com/cosmos/chain-registry/master/testnets/uniontestnet/images/union.png" } diff --git a/app/src/lib/wallet/cosmos/config.ts b/app/src/lib/wallet/cosmos/config.ts index 2c46f0db57..56fdac08cf 100644 --- a/app/src/lib/wallet/cosmos/config.ts +++ b/app/src/lib/wallet/cosmos/config.ts @@ -1,8 +1,8 @@ -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"; +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 = [ { @@ -33,7 +33,7 @@ function createCosmosStore( } ) { console.log("[cosmosStore] previousState", previousState) - const {subscribe, set, update} = persisted("cosmos-store", previousState, { + const { subscribe, set, update } = persisted("cosmos-store", previousState, { syncTabs: true, storage: "session" }) @@ -43,26 +43,26 @@ function createCosmosStore( subscribe, connect: async (walletId: string) => { if (!walletId || (walletId !== "keplr" && walletId !== "leap")) return - update(v => ({...v, connectionStatus: "connecting", connectedWallet: walletId})) - const walletApi = window[walletId]; + update(v => ({ ...v, connectionStatus: "connecting", connectedWallet: walletId })) + const walletApi = window[walletId] if (!walletApi) { alert(`Please install ${walletId} wallet`) - return update(v => ({...v, connectionStatus: "disconnected"})) + return update(v => ({ ...v, connectionStatus: "disconnected" })) } const chainInfoMap = { keplr: keplrChainInfo, leap: leapChainInfo - }; - const chainInfo = chainInfoMap[walletId]; + } + const chainInfo = chainInfoMap[walletId] if (!chainInfo) { - alert('Chain information is missing for the selected wallet.'); - return update(v => ({...v, connectionStatus: "disconnected"})); + alert("Chain information is missing for the selected wallet.") + return update(v => ({ ...v, connectionStatus: "disconnected" })) } try { - await walletApi.experimentalSuggestChain(chainInfo); + await walletApi.experimentalSuggestChain(chainInfo) await walletApi.enable(["union-testnet-8"]) } catch (e) { - return update(v => ({...v, connectionStatus: "disconnected"})); + return update(v => ({ ...v, connectionStatus: "disconnected" })) } const account = await walletApi.getKey("union-testnet-8") update(v => ({ @@ -74,16 +74,15 @@ function createCosmosStore( await sleep(2_000) }, disconnect: async () => { - const cosmosWalletId = get({subscribe}).connectedWallet as CosmosWalletId - console.log({cosmosWalletId}) + const cosmosWalletId = get({ subscribe }).connectedWallet as CosmosWalletId console.log("[cosmos] cosmosDisconnectClick", get(cosmosStore)) if (cosmosWalletId && cosmosWalletId === "keplr" && window[cosmosWalletId]) { await window[cosmosWalletId]?.disable("union-testnet-8") - update(v => ({...v, connectedWallet: "none", connectionStatus: "disconnected"})) + update(v => ({ ...v, connectedWallet: "none", connectionStatus: "disconnected" })) } if (cosmosWalletId && cosmosWalletId === "leap" && window[cosmosWalletId]) { await window[cosmosWalletId]?.disconnect("union-testnet-8") - update(v => ({...v, connectedWallet: "none", connectionStatus: "disconnected"})) + update(v => ({ ...v, connectedWallet: "none", connectionStatus: "disconnected" })) } } } @@ -91,4 +90,3 @@ function createCosmosStore( export const cosmosStore = createCosmosStore() // cosmosStore.subscribe(value => localStorage.setItem("cosmos-config", JSON.stringify(value))) - diff --git a/dictionary.txt b/dictionary.txt index 2ba4fc35e7..41a236a546 100644 --- a/dictionary.txt +++ b/dictionary.txt @@ -1,3 +1,4 @@ + 0xbonlulu 0xc0dejug 0xkaiserkarel @@ -1076,8 +1077,14 @@ unionmodule unionmodulekeeper unionmoduletypes unionp +unionpub unionsimulation unionstaking +uniontestnet +unionvalcons +unionvalconspub +unionvaloper +unionvaloperpub unionvisor unittests unjail