Skip to content

Commit

Permalink
feat: magic wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRalee committed Sep 16, 2024
1 parent c448b10 commit 6b31a9c
Show file tree
Hide file tree
Showing 8 changed files with 821 additions and 35 deletions.
3 changes: 3 additions & 0 deletions packages/wallet-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"@ledgerhq/hw-transport": "6.30.4",
"@ledgerhq/hw-transport-webhid": "6.28.4",
"@ledgerhq/hw-transport-webusb": "6.28.4",
"@magic-ext/cosmos": "23.9.1",
"@magic-ext/oauth2": "9.9.0",
"@metamask/eth-sig-util": "^4.0.0",
"@solana/wallet-adapter-wallets": "0.19.30",
"@toruslabs/torus-embed": "^1.39.0",
Expand All @@ -65,6 +67,7 @@
"hdkey": "^2.0.1",
"link-module-alias": "^1.2.0",
"long": "^5.2.1",
"magic-sdk": "28.9.0",
"shx": "^0.3.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet-ts/src/strategies/types/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface ConcreteCosmosWalletStrategy {
/**
* The accounts from the wallet (addresses)
*/
getAddresses(): Promise<string[]>
getAddresses(args?: unknown): Promise<string[]>

/**
* Return the WalletDeviceType connected on the
Expand Down
56 changes: 33 additions & 23 deletions packages/wallet-ts/src/strategies/wallet-strategy/WalletStrategy.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types'
import { TxRaw, TxResponse } from '@injectivelabs/sdk-ts'
import { DirectSignResponse } from '@cosmjs/proto-signing'
import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types'
import { GeneralException, WalletException } from '@injectivelabs/exceptions'
import { TxRaw, TxResponse } from '@injectivelabs/sdk-ts'
import Okx from './strategies/Okx'
import Leap from './strategies/Leap'
import Keplr from './strategies/Keplr'
import Ninji from './strategies/Ninji'
import Torus from './strategies/Torus'
import Trezor from './strategies/Trezor'
import BitGet from './strategies/BitGet'
import Phantom from './strategies/Phantom'
import Metamask from './strategies/Metamask'
import PrivateKey from './strategies/PrivateKey'
import TrustWallet from './strategies/TrustWallet'
import Cosmostation from './strategies/Cosmostation'
import LedgerCosmos from './strategies/LedgerCosmos'
import WalletConnect from './strategies/WalletConnect'
import LedgerLive from './strategies/Ledger/LedgerLive'
import LedgerLegacy from './strategies/Ledger/LedgerLegacy'
import Magic from './strategies/Magic'
import { isEthWallet, isCosmosWallet } from './utils'
import { Wallet, WalletDeviceType } from '../../types/enums'
import { MagicMetadata, SendTransactionOptions } from './types'
import {
WalletStrategyOptions,
ConcreteWalletStrategy,
onAccountChangeCallback,
onChainIdChangeCallback,
WalletStrategyArguments,
EthereumWalletStrategyArgs,
WalletStrategyEthereumOptions,
WalletStrategyOptions,
} from '../types'
import Keplr from './strategies/Keplr'
import Leap from './strategies/Leap'
import Ninji from './strategies/Ninji'
import Trezor from './strategies/Trezor'
import PrivateKey from './strategies/PrivateKey'
import LedgerLive from './strategies/Ledger/LedgerLive'
import LedgerLegacy from './strategies/Ledger/LedgerLegacy'
import Torus from './strategies/Torus'
import Phantom from './strategies/Phantom'
import Okx from './strategies/Okx'
import BitGet from './strategies/BitGet'
import Cosmostation from './strategies/Cosmostation'
import LedgerCosmos from './strategies/LedgerCosmos'
import WalletConnect from './strategies/WalletConnect'
import { Wallet, WalletDeviceType } from '../../types/enums'
import { isEthWallet, isCosmosWallet } from './utils'
import { SendTransactionOptions } from './types'

const getInitialWallet = (args: WalletStrategyArguments): Wallet => {
if (args.wallet) {
Expand Down Expand Up @@ -120,6 +121,15 @@ const createStrategy = ({
return new Leap({ ...args })
case Wallet.Ninji:
return new Ninji({ ...args })
case Wallet.Magic:
if (!args.options?.metadata?.magic) {
return undefined
}

return new Magic({
...args,
metadata: args.options.metadata.magic as MagicMetadata,
})
default:
return undefined
}
Expand Down Expand Up @@ -192,8 +202,8 @@ export default class WalletStrategy {
return this.strategies[this.wallet] as ConcreteWalletStrategy
}

public getAddresses(): Promise<AccountAddress[]> {
return this.getStrategy().getAddresses()
public getAddresses(args?: unknown): Promise<AccountAddress[]> {
return this.getStrategy().getAddresses(args)
}

public getWalletDeviceType(): Promise<WalletDeviceType> {
Expand All @@ -213,7 +223,7 @@ export default class WalletStrategy {
): Promise<AccountAddress[]> {
await this.getStrategy().enable(args)

return this.getStrategy().getAddresses()
return this.getStrategy().getAddresses(args)
}

public getEthereumChainId(): Promise<string> {
Expand Down
Loading

0 comments on commit 6b31a9c

Please sign in to comment.