diff --git a/docs/docs/change-log.md b/docs/docs/change-log.md index 597d529..5eb0296 100644 --- a/docs/docs/change-log.md +++ b/docs/docs/change-log.md @@ -4,6 +4,10 @@ sidebar_position: 8 # Changelog +## Version 0.1.19 + +- Added Compass wallet integration + ## Version 0.1.18 - Added Wallet connect mobile clot integration diff --git a/docs/docs/types/walletType.md b/docs/docs/types/walletType.md index 2e56d8b..4e248d4 100644 --- a/docs/docs/types/walletType.md +++ b/docs/docs/types/walletType.md @@ -51,5 +51,6 @@ enum WalletType { XDEFI = "xdefi", CAPSULE = "capsule", COSMIFRAME = "cosmiframe", + COMPASS = "compass", } ``` diff --git a/example/next/package.json b/example/next/package.json index 11521c0..529e406 100644 --- a/example/next/package.json +++ b/example/next/package.json @@ -6,7 +6,8 @@ "dev": "next dev", "export:docs": "next build && next export --outdir ../../docs/build/examples/next", "lint": "eslint --fix \"**/*.{ts,tsx}\"", - "start": "next start" + "start": "next start", + "postinstall": "graz generate -g" }, "dependencies": { "@chakra-ui/react": "^2.8.1", diff --git a/example/next/ui/connect-button.tsx b/example/next/ui/connect-button.tsx index f1385cc..afd6dc4 100644 --- a/example/next/ui/connect-button.tsx +++ b/example/next/ui/connect-button.tsx @@ -89,6 +89,7 @@ export const ConnectButton: FC = () => { ) : null} {wallets.capsule ? : null} {wallets.cosmiframe ? : null} + {wallets.compass ? : null} diff --git a/example/starter/public/assets/wallet-icon-compass.png b/example/starter/public/assets/wallet-icon-compass.png new file mode 100644 index 0000000..9b6e593 Binary files /dev/null and b/example/starter/public/assets/wallet-icon-compass.png differ diff --git a/example/starter/src/utils/graz.ts b/example/starter/src/utils/graz.ts index a6a03a8..863c3e6 100644 --- a/example/starter/src/utils/graz.ts +++ b/example/starter/src/utils/graz.ts @@ -69,4 +69,8 @@ export const listedWallets = { name: "DAO DAO", imgSrc: "/assets/wallet-icon-daodao.png", }, + [WalletType.COMPASS]: { + name: "Compass", + imgSrc: "/assets/wallet-icon-compass.png", + }, }; diff --git a/packages/graz/package.json b/packages/graz/package.json index 31b42e2..6536205 100644 --- a/packages/graz/package.json +++ b/packages/graz/package.json @@ -1,7 +1,7 @@ { "name": "graz", "description": "React hooks for Cosmos", - "version": "0.1.18", + "version": "0.1.19", "author": "Griko Nibras ", "repository": "https://github.com/graz-sh/graz.git", "homepage": "https://github.com/graz-sh/graz", @@ -48,7 +48,7 @@ "@cosmjs/proto-signing": "*", "@cosmjs/stargate": "*", "@cosmjs/tendermint-rpc": "*", - "@leapwallet/cosmos-social-login-capsule-provider": "^0.0.37", + "@leapwallet/cosmos-social-login-capsule-provider": "^0.0.39", "react": ">=17" }, "dependencies": { diff --git a/packages/graz/src/actions/wallet/compass.ts b/packages/graz/src/actions/wallet/compass.ts new file mode 100644 index 0000000..d68cfef --- /dev/null +++ b/packages/graz/src/actions/wallet/compass.ts @@ -0,0 +1,46 @@ +import type { KeplrIntereactionOptions } from "@keplr-wallet/types"; + +import { useGrazInternalStore } from "../../store"; +import type { Wallet } from "../../types/wallet"; +import { clearSession } from "."; + +/** + * Function to return Compass object (which is {@link Wallet}) and throws and error if it does not exist on `window`. + * + * @example + * ```ts + * try { + * const compass = getCompass(); + * } catch (error: Error) { + * console.error(error.message); + * } + * ``` + * + * @see https://docs.leapwallet.io/cosmos/for-dapps-connect-to-leap/add-leap-to-existing-keplr-integration + */ +export const getCompass = (): Wallet => { + if (typeof window.compass !== "undefined") { + const compass = window.compass; + const subscription: (reconnect: () => void) => () => void = (reconnect) => { + const listener = () => { + clearSession(); + reconnect(); + }; + window.addEventListener("leap_keystorechange", listener); + return () => { + window.removeEventListener("leap_keystorechange", listener); + }; + }; + const setDefaultOptions = (options: KeplrIntereactionOptions) => { + compass.defaultOptions = options; + }; + const res = Object.assign(compass, { + subscription, + setDefaultOptions, + }); + return res; + } + + useGrazInternalStore.getState()._notFoundFn(); + throw new Error("window.leap is not defined"); +}; diff --git a/packages/graz/src/actions/wallet/index.ts b/packages/graz/src/actions/wallet/index.ts index 6e2ca72..c935152 100644 --- a/packages/graz/src/actions/wallet/index.ts +++ b/packages/graz/src/actions/wallet/index.ts @@ -3,6 +3,7 @@ import { grazSessionDefaultValues, useGrazInternalStore, useGrazSessionStore } f import type { Wallet } from "../../types/wallet"; import { WALLET_TYPES, WalletType } from "../../types/wallet"; import { getCapsule } from "./capsule"; +import { getCompass } from "./compass"; import { getCosmiframe } from "./cosmiframe"; import { getMetamaskSnapCosmos } from "./cosmos-metamask-snap"; import { getCosmostation } from "./cosmostation"; @@ -101,6 +102,9 @@ export const getWallet = (type: WalletType = useGrazInternalStore.getState().wal case WalletType.COSMIFRAME: { return getCosmiframe(); } + case WalletType.COMPASS: { + return getCompass(); + } default: { throw new Error("Unknown wallet type"); } diff --git a/packages/graz/src/provider/events.tsx b/packages/graz/src/provider/events.tsx index 8c12d32..d392384 100644 --- a/packages/graz/src/provider/events.tsx +++ b/packages/graz/src/provider/events.tsx @@ -15,6 +15,7 @@ import { getXDefi } from "../actions/wallet/xdefi"; import { RECONNECT_SESSION_KEY } from "../constant"; import { useGrazInternalStore, useGrazSessionStore } from "../store"; import { WalletType } from "../types/wallet"; +import { getCompass } from "../actions/wallet/compass"; /** * Graz custom hook to track `keplr_keystorechange`, `leap_keystorechange`, `accountChanged` event and reconnect state @@ -90,6 +91,11 @@ export const useGrazEvents = () => { getLeap().subscription?.(() => { void reconnect({ onError: _onReconnectFailed }); }); + } + if (_reconnectConnector === WalletType.COMPASS) { + getCompass().subscription?.(() => { + void reconnect({ onError: _onReconnectFailed }); + }); } if (_reconnectConnector === WalletType.VECTIS) { getVectis().subscription?.(() => { diff --git a/packages/graz/src/types/wallet.ts b/packages/graz/src/types/wallet.ts index 0c88691..85deff8 100644 --- a/packages/graz/src/types/wallet.ts +++ b/packages/graz/src/types/wallet.ts @@ -22,6 +22,7 @@ export enum WalletType { XDEFI = "xdefi", CAPSULE = "capsule", COSMIFRAME = "cosmiframe", + COMPASS = "compass", } export const WALLET_TYPES = [ @@ -40,6 +41,7 @@ export const WALLET_TYPES = [ WalletType.CAPSULE, WalletType.METAMASK_SNAP_COSMOS, WalletType.COSMIFRAME, + WalletType.COMPASS, ]; export type Wallet = Pick< diff --git a/packages/graz/types/global.d.ts b/packages/graz/types/global.d.ts index 2ddfd86..3d21f20 100644 --- a/packages/graz/types/global.d.ts +++ b/packages/graz/types/global.d.ts @@ -6,6 +6,7 @@ type VectisWindow = import("@vectis/extension-client").VectisWindow; declare global { interface Window extends KeplrWindow, VectisWindow { leap?: KeplrWindow["keplr"]; + compass?: KeplrWindow["keplr"]; cosmostation?: { cosmos: { on: (type: string, listener: EventListenerOrEventListenerObject) => void; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 96bef84..988cf5d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + importers: .: @@ -243,8 +247,8 @@ importers: specifier: ^0.12.23 version: 0.12.23 '@leapwallet/cosmos-social-login-capsule-provider': - specifier: ^0.0.33 - version: 0.0.33(@cosmjs/encoding@0.31.3)(@cosmjs/proto-signing@0.31.0)(fp-ts@2.16.5) + specifier: ^0.0.39 + version: 0.0.39(@cosmjs/encoding@0.31.3)(@cosmjs/proto-signing@0.31.0)(fp-ts@2.16.5) '@metamask/providers': specifier: ^12.0.0 version: 12.0.0 @@ -6812,8 +6816,8 @@ packages: - zod dev: false - /@leapwallet/cosmos-social-login-capsule-provider@0.0.33(@cosmjs/encoding@0.31.3)(@cosmjs/proto-signing@0.31.0)(fp-ts@2.16.5): - resolution: {integrity: sha512-vHutBY6S6a1w+fhVsF78u/plGR4xmK4+/22pJaiaZCeekBTJRgLGr7bmloEswOQlZUUS6VGL29lm76r111bbrQ==} + /@leapwallet/cosmos-social-login-capsule-provider@0.0.39(@cosmjs/encoding@0.31.3)(@cosmjs/proto-signing@0.31.0)(fp-ts@2.16.5): + resolution: {integrity: sha512-7u9ZhiBHK7MeCNFNcnN4ttS11LITL5P6NtBwZ331MppAsGqRkexJQq6fofDZIiGaKiBqAp4qsFKEVM0fohOZBA==} dependencies: '@cosmjs/amino': 0.31.3 '@leapwallet/cosmos-social-login-core': 0.0.1 @@ -8991,7 +8995,7 @@ packages: /assert@2.1.0: resolution: {integrity: sha512-eLHpSK/Y4nhMJ07gDaAzoX/XAKS8PSaojml3M0DM4JpV1LAi5JOJ/p6H/XWrl8L+DzVEvVCW1z3vWAaB9oTsQw==} dependencies: - call-bind: 1.0.2 + call-bind: 1.0.7 is-nan: 1.3.2 object-is: 1.1.5 object.assign: 4.1.4 @@ -18588,7 +18592,3 @@ packages: /zwitch@1.0.5: resolution: {integrity: sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==} dev: false - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false