-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
8 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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { OfflineDirectSigner } from "@cosmjs/proto-signing"; | ||
import type { DeliverTxResponse } from "@cosmjs/stargate"; | ||
import type { Chain } from "@initia/initia-registry-types"; | ||
|
||
import { useGrazInternalStore } from "../../store"; | ||
import type { SignAminoParams, SignDirectParams, Wallet } from "../../types/wallet"; | ||
import { clearSession } from "."; | ||
|
||
export interface InitiaWallet { | ||
version: string; | ||
getAddress: (chainId: string) => Promise<string>; | ||
signAndBroadcast: (chainId: string, txBody: Uint8Array) => Promise<DeliverTxResponse>; | ||
getOfflineSigner: (chainId: string) => OfflineDirectSigner; | ||
requestAddInitiaLayer: (chain: Partial<Chain>) => Promise<void>; | ||
signArbitrary: (data: string | Uint8Array) => Promise<string>; | ||
verifyArbitrary: (data: string | Uint8Array, signature: string) => Promise<boolean>; | ||
} | ||
|
||
export const getInitia = (): Wallet => { | ||
if (typeof window.initia !== "undefined") { | ||
const initia = window.initia; | ||
|
||
const enable = async () => {}; | ||
const getKey = async (chainId: string) => {}; | ||
const getOfflineSigner = (chainId: string) => {}; | ||
const getOfflineSignerAuto = async (chainId: string) => {}; | ||
const getOfflineSignerOnlyAmino = (chainId: string) => {}; | ||
const experimentalSuggestChain = (chain: Partial<Chain>) => {}; | ||
const signDirect = async (...args: SignDirectParams) => {}; | ||
const signAmino = async (...args: SignAminoParams) => {}; | ||
|
||
const subscription: (reconnect: () => void) => () => void = (reconnect) => { | ||
const listener = () => { | ||
clearSession(); | ||
reconnect(); | ||
}; | ||
window.addEventListener("initia_keystorechange", listener); | ||
return () => { | ||
window.removeEventListener("initia_keystorechange", listener); | ||
}; | ||
}; | ||
} | ||
useGrazInternalStore.getState()._notFoundFn(); | ||
throw new Error("window.initia is not defined"); | ||
}; |
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 |
---|---|---|
@@ -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 okxwallet object (which is {@link Wallet}) and throws and error if it does not exist on `window`. | ||
* | ||
* @example | ||
* ```ts | ||
* try { | ||
* const okxWallet = getOkx(); | ||
* } catch (error: Error) { | ||
* console.error(error.message); | ||
* } | ||
* ``` | ||
* | ||
* @see https://www.okx.com/web3/build/docs/sdks/chains/cosmos/provider | ||
*/ | ||
export const getOkx = (): Wallet => { | ||
if (typeof window.okxwallet?.keplr !== "undefined") { | ||
const okxWallet = window.okxwallet.keplr; | ||
const subscription: (reconnect: () => void) => () => void = (reconnect) => { | ||
const listener = () => { | ||
clearSession(); | ||
reconnect(); | ||
}; | ||
window.okxwallet?.on("accountsChanged", listener); | ||
return () => { | ||
window.okxwallet?.removeListener("accountsChanged", listener); | ||
}; | ||
}; | ||
|
||
const setDefaultOptions = (options: KeplrIntereactionOptions) => { | ||
okxWallet.defaultOptions = options; | ||
}; | ||
const res = Object.assign(okxWallet, { | ||
subscription, | ||
setDefaultOptions, | ||
}); | ||
return res; | ||
} | ||
|
||
useGrazInternalStore.getState()._notFoundFn(); | ||
throw new Error("window.okxwallet.keplr is not defined"); | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.