Skip to content

Commit

Permalink
chore: wallet-cosmos add support for owallet
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRalee committed Oct 25, 2024
1 parent 7152d3e commit ec17ff3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/wallets/wallet-base/src/types/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum Wallet {
Ledger = 'ledger',
BitGet = 'BitGet',
Trezor = 'trezor',
OWallet = 'owallet',
Phantom = 'phantom',
Metamask = 'metamask',
OkxWallet = 'okx-wallet',
Expand Down
1 change: 1 addition & 0 deletions packages/wallets/wallet-cosmos/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { CosmosWallet } from './wallet'
export { CosmosWalletStrategy } from './strategy/strategy'
6 changes: 3 additions & 3 deletions packages/wallets/wallet-cosmos/src/strategy/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import type { DirectSignResponse } from '@cosmjs/proto-signing'
import { CosmosWallet } from './../wallet'

const cosmosWallets = [Wallet.Leap, Wallet.Ninji, Wallet.Keplr]
const cosmosWallets = [Wallet.Leap, Wallet.Ninji, Wallet.Keplr, Wallet.OWallet]

export class CosmosWalletStrategy
extends BaseConcreteStrategy
Expand Down Expand Up @@ -85,7 +85,7 @@ export class CosmosWalletStrategy
)
}

if (wallet === Wallet.Keplr) {
if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) {
window.removeEventListener(
'keplr_keystorechange',
this.listeners[WalletEventListener.AccountChange],
Expand Down Expand Up @@ -305,7 +305,7 @@ export class CosmosWalletStrategy
window.ninji.on('accountsChanged', listener)
}

if (wallet === Wallet.Keplr) {
if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) {
window.addEventListener('keplr_keystorechange', listener)
}

Expand Down
34 changes: 29 additions & 5 deletions packages/wallets/wallet-cosmos/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const $window = (typeof window !== 'undefined' ? window : {}) as Window & {
keplr?: Keplr
ninji?: Keplr
leap?: Keplr
owallet?: Keplr
}

export class CosmosWallet {
Expand Down Expand Up @@ -65,13 +66,20 @@ export class CosmosWallet {
const { chainId, wallet } = this
const chainName = chainId.split('-')

const context =
wallet === Wallet.Keplr
? 'https://chains.keplr.app/'
: wallet === Wallet.OWallet
? 'https://owallet.io/'
: undefined

throw new CosmosWalletException(
new Error(
`${wallet} may not support ${
chainName[0] || chainId
} network. Please check if the chain can be added.`,
),
{ context: 'https://chains.keplr.app/' },
context ? { context } : {},
)
}

Expand Down Expand Up @@ -126,7 +134,7 @@ export class CosmosWallet {
public async getOfflineAminoSigner(): Promise<OfflineAminoSigner> {
const { chainId, wallet } = this

if (wallet !== Wallet.Keplr) {
if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) {
throw new CosmosWalletException(
new Error(`getOfflineAminoSigner is not support on ${wallet}`),
)
Expand Down Expand Up @@ -232,7 +240,7 @@ export class CosmosWallet {
const { chainId, wallet } = this
const cosmosWallet = await this.getCosmosWallet()

if (wallet !== Wallet.Keplr) {
if (![Wallet.Keplr, Wallet.OWallet].includes(wallet)) {
throw new CosmosWalletException(
new Error(
`signAndBroadcastAminoUsingCosmjs is not support on ${wallet}`,
Expand Down Expand Up @@ -348,6 +356,10 @@ export class CosmosWallet {

let cosmos = undefined

if (wallet === Wallet.OWallet) {
cosmos = $window.owallet
}

if (wallet === Wallet.Keplr) {
cosmos = $window.keplr
}
Expand All @@ -374,10 +386,16 @@ export class CosmosWallet {
return cosmos! as Keplr
}

// @bojan q: should we retrict this to Keplr only
public async disableGasCheck() {
const { wallet } = this
const cosmosWallet = await this.getCosmosWallet()

if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) {
throw new CosmosWalletException(
new Error(`disableGasCheck is not support on ${wallet}`),
)
}

// Temporary disable tx gas check for fee delegation purposes
cosmosWallet.defaultOptions = {
...cosmosWallet.defaultOptions,
Expand All @@ -388,10 +406,16 @@ export class CosmosWallet {
}
}

// @bojan q: should we retrict this to Keplr only
public async enableGasCheck() {
const { wallet } = this
const cosmosWallet = await this.getCosmosWallet()

if ([Wallet.Keplr, Wallet.OWallet].includes(wallet)) {
throw new CosmosWalletException(
new Error(`enableGasCheck is not support on ${wallet}`),
)
}

// Temporary disable tx gas check for fee delegation purposes
cosmosWallet.defaultOptions = {
...cosmosWallet.defaultOptions,
Expand Down
1 change: 1 addition & 0 deletions packages/wallets/wallet-cosmostation/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { CosmostationWallet } from './wallet'
export { Cosmostation as CosmostationWalletStrategy } from './strategy/strategy'
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ const createStrategy = ({
return new CosmosWalletStrategy({ ...args, wallet: Wallet.Leap })
case Wallet.Ninji:
return new CosmosWalletStrategy({ ...args, wallet: Wallet.Ninji })
case Wallet.OWallet:
return new CosmosWalletStrategy({ ...args, wallet: Wallet.OWallet })
case Wallet.Magic:
if (
!args.options?.metadata?.magic ||
Expand Down

0 comments on commit ec17ff3

Please sign in to comment.