Skip to content

Commit

Permalink
bump keplr version (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
codingki authored Nov 24, 2024
2 parents 53a2740 + 277e9bc commit b98ca08
Show file tree
Hide file tree
Showing 13 changed files with 911 additions and 187 deletions.
6 changes: 3 additions & 3 deletions packages/graz/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "graz",
"description": "React hooks for Cosmos",
"version": "0.1.27",
"version": "0.1.28",
"author": "Griko Nibras <[email protected]>",
"repository": "https://github.com/graz-sh/graz.git",
"homepage": "https://github.com/graz-sh/graz",
Expand Down Expand Up @@ -52,10 +52,10 @@
"react": ">=17"
},
"dependencies": {
"@keplr-wallet/types": "0.12.156",
"@cosmsnap/snapper": "0.1.29",
"@dao-dao/cosmiframe": "0.1.0",
"@keplr-wallet/cosmos": "0.12.20",
"@keplr-wallet/types": "0.12.23",
"@keplr-wallet/cosmos": "0.12.156",
"@metamask/providers": "12.0.0",
"@tanstack/react-query": "4.35.0",
"@terra-money/station-connector": "1.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/graz/src/actions/account.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { OfflineDirectSigner } from "@cosmjs/proto-signing";
import type { ChainInfo, Key, OfflineAminoSigner } from "@keplr-wallet/types";
import type { ChainInfo, OfflineAminoSigner } from "@keplr-wallet/types";

import { RECONNECT_SESSION_KEY } from "../constant";
import { grazSessionDefaultValues, useGrazInternalStore, useGrazSessionStore } from "../store";
import type { Maybe } from "../types/core";
import type { WalletType } from "../types/wallet";
import type { Key, WalletType } from "../types/wallet";
import type { ChainId } from "../utils/multi-chain";
import { checkWallet, getWallet, isCapsule, isWalletConnect } from "./wallet";

Expand Down
4 changes: 2 additions & 2 deletions packages/graz/src/actions/wallet/capsule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
} from "@cosmjs/amino";
import { fromBech32 } from "@cosmjs/encoding";
import type { DirectSignResponse } from "@cosmjs/proto-signing";
import type { Keplr, Key } from "@keplr-wallet/types";
import type { Keplr } from "@keplr-wallet/types";

import { RECONNECT_SESSION_KEY } from "../../constant";
import { useGrazInternalStore, useGrazSessionStore } from "../../store";
import type { SignAminoParams, SignDirectParams, Wallet } from "../../types/wallet";
import type { Key, SignAminoParams, SignDirectParams, Wallet } from "../../types/wallet";
import { WalletType } from "../../types/wallet";

export const getCapsule = (): Wallet => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ export const getMetamaskSnapCosmos = (): Wallet => {
enable,
getOfflineSigner: (chainId: string) => cosmos.getOfflineSigner(chainId),
experimentalSuggestChain: async (chainInfo) => {
await cosmos.experimentalSuggestChain(chainInfo);
if (!chainInfo.bech32Config) throw new Error("Bech32Config is required");
if (!chainInfo.stakeCurrency) throw new Error("StakeCurrency is required");
await cosmos.experimentalSuggestChain({
...chainInfo,
stakeCurrency: chainInfo.stakeCurrency,
bech32Config: chainInfo.bech32Config,
});
},
signAmino: async (chainId, signer, signDoc) => {
return cosmos.signAmino(chainId, signer, signDoc);
Expand Down
12 changes: 2 additions & 10 deletions packages/graz/src/actions/wallet/leap-metamask-snap/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import type {
AccountData,
Algo,
AminoSignResponse,
DirectSignResponse,
Keplr,
Key,
StdSignDoc,
} from "@keplr-wallet/types";
import type { AccountData, Algo, AminoSignResponse, DirectSignResponse, Keplr, StdSignDoc } from "@keplr-wallet/types";
// eslint-disable-next-line import/no-named-as-default
import Long from "long";

import { useGrazInternalStore } from "../../../store";
import type { KnownKeys, SignAminoParams, SignDirectParams, Wallet } from "../../../types/wallet";
import type { Key, KnownKeys, SignAminoParams, SignDirectParams, Wallet } from "../../../types/wallet";
import type { ChainId } from "../../../utils/multi-chain";
import type { GetSnapsResponse, Snap } from "./types";

Expand Down
8 changes: 6 additions & 2 deletions packages/graz/src/actions/wallet/station.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ChainInfo, DirectSignResponse, KeplrSignOptions, Key, SignDoc, StdSignDoc } from "@keplr-wallet/types";
import type { ChainInfo, DirectSignResponse, KeplrSignOptions, SignDoc, StdSignDoc } from "@keplr-wallet/types";
import type { ChainInfoResponse } from "@terra-money/station-connector/keplrConnector";

import { useGrazInternalStore } from "../../store";
import type { Wallet } from "../../types/wallet";
import type { Key, Wallet } from "../../types/wallet";
import { clearSession } from ".";

/**
Expand Down Expand Up @@ -60,7 +60,11 @@ export const getStation = (): Wallet => {

const experimentalSuggestChain = async (chainInfo: ChainInfo) => {
try {
if (!chainInfo.bech32Config) throw new Error("Bech32Config is required");
if (!chainInfo.stakeCurrency) throw new Error("StakeCurrency is required");

const chainInfoResponse: ChainInfoResponse = Object.assign(chainInfo, {
bech32Config: chainInfo.bech32Config,
chainSymbolImageUrl: chainInfo.chainSymbolImageUrl || "",
stakeCurrency: {
coinDecimals: chainInfo.stakeCurrency.coinDecimals,
Expand Down
21 changes: 15 additions & 6 deletions packages/graz/src/actions/wallet/vectis.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { AminoSignResponse } from "@cosmjs/amino";
import { fromBech32 } from "@cosmjs/encoding";
import type { DirectSignResponse } from "@cosmjs/proto-signing";
import type { Key } from "@keplr-wallet/types";
import Long from "long";

import { useGrazInternalStore } from "../../store";
import type { SignAminoParams, SignDirectParams, Wallet } from "../../types/wallet";
import type { Key, SignAminoParams, SignDirectParams, Wallet } from "../../types/wallet";
import { clearSession } from ".";
import { ChainInfo } from "@vectis/extension-client";

/**
* Function to return {@link Wallet} object and throws and error if it does not exist on `window`.
Expand Down Expand Up @@ -36,17 +36,26 @@ export const getVectis = (): Wallet => {
};
};
const getOfflineSignerOnlyAmino = (...args: Parameters<Wallet["getOfflineSignerOnlyAmino"]>) => {
return vectis.getOfflineSignerAmino(...args);
const chainId = args[0];
return vectis.getOfflineSignerAmino(chainId);
};

const experimentalSuggestChain = async (...args: Parameters<Wallet["experimentalSuggestChain"]>) => {
const [chainInfo] = args;
const adaptChainInfo = {
...chainInfo,
if (!chainInfo.bech32Config) throw new Error("Bech32Config is required");
if (!chainInfo.stakeCurrency) throw new Error("StakeCurrency is required");
const adaptChainInfo: ChainInfo = {
rpcUrl: chainInfo.rpc,
restUrl: chainInfo.rest,
prettyName: chainInfo.chainName.replace(" ", ""),
bech32Prefix: chainInfo.bech32Config.bech32PrefixAccAddr,
bech32Prefix: chainInfo.bech32Config?.bech32PrefixAccAddr,
currencies: chainInfo.currencies,
feeCurrencies: chainInfo.feeCurrencies,
chainId: chainInfo.chainId,
chainName: chainInfo.chainName,
bip44: chainInfo.bip44,
stakeCurrency: chainInfo.stakeCurrency,
features: chainInfo.features,
};
return vectis.suggestChains([adaptChainInfo]);
};
Expand Down
4 changes: 2 additions & 2 deletions packages/graz/src/actions/wallet/wallet-connect/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { AminoSignResponse } from "@cosmjs/amino";
import type { AccountData, Algo, DirectSignResponse } from "@cosmjs/proto-signing";
import type { Keplr, Key } from "@keplr-wallet/types";
import type { Keplr } from "@keplr-wallet/types";
import { SignClient } from "@walletconnect/sign-client";
import type { ISignClient, SignClientTypes } from "@walletconnect/types";
import { getSdkError } from "@walletconnect/utils";
import Long from "long";

import { useGrazInternalStore, useGrazSessionStore } from "../../../store";
import { type SignAminoParams, type SignDirectParams, type Wallet, WalletType } from "../../../types/wallet";
import { Key, type SignAminoParams, type SignDirectParams, type Wallet, WalletType } from "../../../types/wallet";
import { isAndroid, isIos, isMobile } from "../../../utils/os";
import { promiseWithTimeout } from "../../../utils/timeout";
import type { GetWalletConnectParams, WalletConnectSignDirectResponse } from "./types";
Expand Down
8 changes: 4 additions & 4 deletions packages/graz/src/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ const generate = async () => {
console.log("🐙\tDetected chain filtering flag, generating only given chain paths...");
}

/** @type {Record<string, ChainInfo>} */
/** @type {Record<string, import("@keplr-wallet/types").ChainInfo>} */
let mainnetRecord;
/** @type {Record<string, ChainInfo>} */
/** @type {Record<string, import("@keplr-wallet/types").ChainInfo>} */
let testnetRecord;

if (args["--endpoint"]) {
Expand Down Expand Up @@ -146,9 +146,9 @@ const generate = async () => {
};

/**
* @param {Record<string, ChainInfo>} chains
* @param {Record<string, import("@keplr-wallet/types").ChainInfo>} chains
* @param {string | undefined} filter
* @returns {Record<string, ChainInfo>}
* @returns {Record<string, import("@keplr-wallet/types").ChainInfo>}
*/
const filterChains = (chains, filter) => {
if (!filter) return chains;
Expand Down
2 changes: 2 additions & 0 deletions packages/graz/src/hooks/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export const useBalances = <TMulti extends MultiChainHookArgs>(
if (!stargateClient) {
throw new Error(`Client is not ready ${_chain.chainId}`);
}
if (!_chain.bech32Config?.bech32PrefixAccAddr) throw new Error(`Bech32Config is missing ${_chain.chainId}`);
const balances = await stargateClient.getAllBalances(
toBech32(_chain.bech32Config.bech32PrefixAccAddr, fromBech32(_address).data),
);
Expand Down Expand Up @@ -423,6 +424,7 @@ export const useBalanceStaked = <TMulti extends MultiChainHookArgs>(
}
const res = await createMultiChainAsyncFunction(Boolean(args?.multiChain), _chains, async (_chain) => {
if (!_client) throw new Error("Client is not ready");
if (!_chain.bech32Config?.bech32PrefixAccAddr) throw new Error(`Bech32Config is missing ${_chain.chainId}`);
const balance = await _client[_chain.chainId]?.getBalanceStaked(
toBech32(_chain.bech32Config.bech32PrefixAccAddr, fromBech32(_address).data),
);
Expand Down
4 changes: 2 additions & 2 deletions packages/graz/src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ChainInfo, Keplr, Key } from "@keplr-wallet/types";
import type { ChainInfo, Keplr } from "@keplr-wallet/types";
import type { CapsuleProvider } from "@leapwallet/cosmos-social-login-capsule-provider";
import type { ISignClient, SignClientTypes } from "@walletconnect/types";
import type { WalletConnectModalConfig } from "@walletconnect/modal";
Expand All @@ -8,7 +8,7 @@ import { createJSONStorage } from "zustand/middleware";
import { persist, subscribeWithSelector } from "zustand/middleware";

import type { Dictionary } from "../types/core";
import { WalletType } from "../types/wallet";
import { Key, WalletType } from "../types/wallet";

export interface ChainConfig {
path?: string;
Expand Down
15 changes: 6 additions & 9 deletions packages/graz/src/types/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Keplr, KeplrIntereactionOptions, Key } from "@keplr-wallet/types";
import type { ChainInfo, Keplr, KeplrIntereactionOptions, Key as KeplrKey } from "@keplr-wallet/types";

export enum WalletType {
KEPLR = "keplr",
Expand Down Expand Up @@ -50,24 +50,21 @@ export const WALLET_TYPES = [

export type Wallet = Pick<
Keplr,
| "enable"
| "getKey"
| "getOfflineSigner"
| "getOfflineSignerAuto"
| "getOfflineSignerOnlyAmino"
| "experimentalSuggestChain"
| "signDirect"
| "signAmino"
"enable" | "getOfflineSigner" | "getOfflineSignerAuto" | "getOfflineSignerOnlyAmino" | "signDirect" | "signAmino"
> & {
experimentalSuggestChain: (chainInfo: Omit<ChainInfo, "nodeProvider">) => Promise<void>;
signArbitrary?: Keplr["signArbitrary"];
subscription?: (reconnect: () => void) => () => void;
init?: () => Promise<unknown>;
disable?: (chainIds?: string | undefined) => Promise<void>;
setDefaultOptions?: (options: KeplrIntereactionOptions) => void;
onAfterLoginSuccessful?: () => Promise<void>;
getKey: (chainId: string) => Promise<Key>;
};

export type SignDirectParams = Parameters<Wallet["signDirect"]>;
export type SignAminoParams = Parameters<Wallet["signAmino"]>;

export type KnownKeys = Record<string, Key>;

export type Key = Omit<KeplrKey, "ethereumHexAddress">;
Loading

0 comments on commit b98ca08

Please sign in to comment.