@sodax/wallet-sdk-react 1.3.0-beta → 1.3.1-beta-rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,11 +1,10 @@
1
- import { ChainId, ChainType, XToken, IEvmWalletProvider, ISuiWalletProvider, IIconWalletProvider, IInjectiveWalletProvider, IStellarWalletProvider, ISolanaWalletProvider, INearWalletProvider, RpcConfig } from '@sodax/types';
1
+ import { ChainId, ChainType, XToken, IBitcoinWalletProvider, IEvmWalletProvider, ISuiWalletProvider, IIconWalletProvider, IInjectiveWalletProvider, IStellarWalletProvider, ISolanaWalletProvider, INearWalletProvider, RpcConfig } from '@sodax/types';
2
2
  import { Config, Connector } from 'wagmi';
3
3
  import { IconService } from 'icon-sdk-js';
4
4
  import { IndexerGrpcAccountPortfolioApi, ChainGrpcWasmApi } from '@injectivelabs/sdk-ts';
5
5
  import { MsgBroadcaster } from '@injectivelabs/wallet-core';
6
6
  import { WalletStrategy } from '@injectivelabs/wallet-strategy';
7
7
  import { Connection } from '@solana/web3.js';
8
- import { AnchorProvider } from '@coral-xyz/anchor';
9
8
  import { WalletContextState } from '@solana/wallet-adapter-react';
10
9
  import { StellarWalletsKit } from '@creit.tech/stellar-wallets-kit';
11
10
  import * as StellarSdk from '@stellar/stellar-sdk';
@@ -21,6 +20,7 @@ declare function getXChainType(xChainId: ChainId | undefined): ChainType | undef
21
20
  type XAccount = {
22
21
  address: string | undefined;
23
22
  xChainType: ChainType | undefined;
23
+ publicKey?: string;
24
24
  };
25
25
  type XConnection = {
26
26
  xAccount: XAccount;
@@ -128,6 +128,109 @@ declare function getXService(xChainType: ChainType): XService;
128
128
  declare const isNativeToken: (xToken: XToken) => boolean;
129
129
  declare const getWagmiChainId: (xChainId: ChainId) => number;
130
130
 
131
+ declare class BitcoinXService extends XService {
132
+ private static instance;
133
+ private rpcUrl;
134
+ private constructor();
135
+ static getInstance(rpcUrl?: string): BitcoinXService;
136
+ getBalance(address: string | undefined, xToken: XToken): Promise<bigint>;
137
+ }
138
+
139
+ /**
140
+ * Abstract base class for Bitcoin wallet connectors.
141
+ * Subclasses implement wallet-specific connection logic (Unisat, Xverse, OKX).
142
+ */
143
+ declare abstract class BitcoinXConnector extends XConnector {
144
+ constructor(name: string, id: string);
145
+ getXService(): BitcoinXService;
146
+ abstract connect(): Promise<XAccount | undefined>;
147
+ abstract disconnect(): Promise<void>;
148
+ /**
149
+ * Returns an IBitcoinWalletProvider instance after connecting.
150
+ * Used by useSpokeProvider to build BitcoinSpokeProvider.
151
+ */
152
+ abstract getWalletProvider(): IBitcoinWalletProvider | undefined;
153
+ /**
154
+ * Recreates a walletProvider from the browser extension window object
155
+ * and stored xAccount data (no connect() call, no popup).
156
+ * Used to restore provider after page reload without requiring reconnect.
157
+ */
158
+ abstract recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
159
+ }
160
+
161
+ interface UnisatWallet {
162
+ getAccounts(): Promise<string[]>;
163
+ getPublicKey(): Promise<string>;
164
+ signPsbt(psbtHex: string, options?: {
165
+ autoFinalized?: boolean;
166
+ }): Promise<string>;
167
+ signMessage(message: string, type?: 'bip322-simple' | 'ecdsa'): Promise<string>;
168
+ requestAccounts(): Promise<string[]>;
169
+ sendBitcoin(address: string, satoshis: number): Promise<string>;
170
+ }
171
+ declare global {
172
+ interface Window {
173
+ unisat?: UnisatWallet;
174
+ }
175
+ }
176
+ declare class UnisatXConnector extends BitcoinXConnector {
177
+ private walletProvider;
178
+ constructor();
179
+ static isAvailable(): boolean;
180
+ get icon(): string;
181
+ connect(): Promise<XAccount | undefined>;
182
+ disconnect(): Promise<void>;
183
+ getWalletProvider(): IBitcoinWalletProvider | undefined;
184
+ recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
185
+ }
186
+
187
+ declare class XverseXConnector extends BitcoinXConnector {
188
+ private walletProvider;
189
+ constructor();
190
+ static isAvailable(): boolean;
191
+ get icon(): string;
192
+ connect(): Promise<XAccount | undefined>;
193
+ disconnect(): Promise<void>;
194
+ getWalletProvider(): IBitcoinWalletProvider | undefined;
195
+ recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
196
+ }
197
+
198
+ interface OKXBitcoinWallet {
199
+ getAccounts(): Promise<string[]>;
200
+ getPublicKey(): Promise<string>;
201
+ signPsbt(psbtHex: string, options?: {
202
+ autoFinalized?: boolean;
203
+ }): Promise<string>;
204
+ signMessage(message: string, type?: 'bip322-simple' | 'ecdsa'): Promise<string>;
205
+ connect(): Promise<{
206
+ address: string;
207
+ publicKey: string;
208
+ }>;
209
+ sendBitcoin(toAddress: string, satoshis: number): Promise<string>;
210
+ }
211
+ declare global {
212
+ interface Window {
213
+ okxwallet?: {
214
+ bitcoin?: OKXBitcoinWallet;
215
+ };
216
+ }
217
+ }
218
+ declare class OKXXConnector extends BitcoinXConnector {
219
+ private walletProvider;
220
+ constructor();
221
+ static isAvailable(): boolean;
222
+ get icon(): string;
223
+ connect(): Promise<XAccount | undefined>;
224
+ disconnect(): Promise<void>;
225
+ getWalletProvider(): IBitcoinWalletProvider | undefined;
226
+ recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
227
+ }
228
+
229
+ /**
230
+ * Hook to return available Bitcoin wallet connectors from the globally registered xService.
231
+ */
232
+ declare function useBitcoinXConnectors(): BitcoinXConnector[];
233
+
131
234
  /**
132
235
  * Service class for handling EVM chain interactions.
133
236
  * Implements singleton pattern and provides methods for wallet/chain operations.
@@ -202,7 +305,6 @@ declare class SolanaXService extends XService {
202
305
  private static instance;
203
306
  connection: Connection | undefined;
204
307
  wallet: WalletContextState | undefined;
205
- provider: AnchorProvider | undefined;
206
308
  private constructor();
207
309
  static getInstance(): SolanaXService;
208
310
  getBalance(address: string | undefined, xToken: XToken): Promise<bigint>;
@@ -273,7 +375,7 @@ declare class SuiXConnector extends XConnector {
273
375
 
274
376
  declare function useXAccount(chainIdentifier?: ChainType | ChainId): XAccount;
275
377
 
276
- declare function useXAccounts(): Partial<Record<"ICON" | "EVM" | "INJECTIVE" | "SUI" | "STELLAR" | "SOLANA" | "NEAR", XAccount>>;
378
+ declare function useXAccounts(): Partial<Record<"ICON" | "EVM" | "INJECTIVE" | "SUI" | "STELLAR" | "SOLANA" | "NEAR" | "BITCOIN", XAccount>>;
277
379
 
278
380
  /**
279
381
  * Hook for connecting to various blockchain wallets across different chains
@@ -427,7 +529,7 @@ declare const useEvmSwitchChain: (expectedXChainId: ChainId) => UseEvmSwitchChai
427
529
  * const walletProvider = useWalletProvider('sui');
428
530
  * ```
429
531
  */
430
- declare function useWalletProvider(spokeChainId: ChainId | undefined): IEvmWalletProvider | ISuiWalletProvider | IIconWalletProvider | IInjectiveWalletProvider | IStellarWalletProvider | ISolanaWalletProvider | INearWalletProvider | undefined;
532
+ declare function useWalletProvider(spokeChainId: ChainId | undefined): IEvmWalletProvider | ISuiWalletProvider | IIconWalletProvider | IInjectiveWalletProvider | IStellarWalletProvider | ISolanaWalletProvider | IBitcoinWalletProvider | INearWalletProvider | undefined;
431
533
 
432
534
  type SignMessageReturnType = `0x${string}` | Uint8Array | string | undefined;
433
535
  declare function useXSignMessage(): UseMutationResult<SignMessageReturnType, Error, {
@@ -466,4 +568,4 @@ declare const SodaxWalletProvider: ({ children, rpcConfig }: {
466
568
  rpcConfig: RpcConfig;
467
569
  }) => React.JSX.Element;
468
570
 
469
- export { type CurrencyKey, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService, SodaxWalletProvider, SolanaXConnector, SolanaXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, WalletId, type XAccount, type XConnection, XConnector, XService, getWagmiChainId, getXChainType, getXService, isNativeToken, switchEthereumChain, useEvmSwitchChain, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
571
+ export { BitcoinXConnector, BitcoinXService, type CurrencyKey, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService, OKXXConnector, SodaxWalletProvider, SolanaXConnector, SolanaXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, UnisatXConnector, WalletId, type XAccount, type XConnection, XConnector, XService, XverseXConnector, getWagmiChainId, getXChainType, getXService, isNativeToken, switchEthereumChain, useBitcoinXConnectors, useEvmSwitchChain, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- import { ChainId, ChainType, XToken, IEvmWalletProvider, ISuiWalletProvider, IIconWalletProvider, IInjectiveWalletProvider, IStellarWalletProvider, ISolanaWalletProvider, INearWalletProvider, RpcConfig } from '@sodax/types';
1
+ import { ChainId, ChainType, XToken, IBitcoinWalletProvider, IEvmWalletProvider, ISuiWalletProvider, IIconWalletProvider, IInjectiveWalletProvider, IStellarWalletProvider, ISolanaWalletProvider, INearWalletProvider, RpcConfig } from '@sodax/types';
2
2
  import { Config, Connector } from 'wagmi';
3
3
  import { IconService } from 'icon-sdk-js';
4
4
  import { IndexerGrpcAccountPortfolioApi, ChainGrpcWasmApi } from '@injectivelabs/sdk-ts';
5
5
  import { MsgBroadcaster } from '@injectivelabs/wallet-core';
6
6
  import { WalletStrategy } from '@injectivelabs/wallet-strategy';
7
7
  import { Connection } from '@solana/web3.js';
8
- import { AnchorProvider } from '@coral-xyz/anchor';
9
8
  import { WalletContextState } from '@solana/wallet-adapter-react';
10
9
  import { StellarWalletsKit } from '@creit.tech/stellar-wallets-kit';
11
10
  import * as StellarSdk from '@stellar/stellar-sdk';
@@ -21,6 +20,7 @@ declare function getXChainType(xChainId: ChainId | undefined): ChainType | undef
21
20
  type XAccount = {
22
21
  address: string | undefined;
23
22
  xChainType: ChainType | undefined;
23
+ publicKey?: string;
24
24
  };
25
25
  type XConnection = {
26
26
  xAccount: XAccount;
@@ -128,6 +128,109 @@ declare function getXService(xChainType: ChainType): XService;
128
128
  declare const isNativeToken: (xToken: XToken) => boolean;
129
129
  declare const getWagmiChainId: (xChainId: ChainId) => number;
130
130
 
131
+ declare class BitcoinXService extends XService {
132
+ private static instance;
133
+ private rpcUrl;
134
+ private constructor();
135
+ static getInstance(rpcUrl?: string): BitcoinXService;
136
+ getBalance(address: string | undefined, xToken: XToken): Promise<bigint>;
137
+ }
138
+
139
+ /**
140
+ * Abstract base class for Bitcoin wallet connectors.
141
+ * Subclasses implement wallet-specific connection logic (Unisat, Xverse, OKX).
142
+ */
143
+ declare abstract class BitcoinXConnector extends XConnector {
144
+ constructor(name: string, id: string);
145
+ getXService(): BitcoinXService;
146
+ abstract connect(): Promise<XAccount | undefined>;
147
+ abstract disconnect(): Promise<void>;
148
+ /**
149
+ * Returns an IBitcoinWalletProvider instance after connecting.
150
+ * Used by useSpokeProvider to build BitcoinSpokeProvider.
151
+ */
152
+ abstract getWalletProvider(): IBitcoinWalletProvider | undefined;
153
+ /**
154
+ * Recreates a walletProvider from the browser extension window object
155
+ * and stored xAccount data (no connect() call, no popup).
156
+ * Used to restore provider after page reload without requiring reconnect.
157
+ */
158
+ abstract recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
159
+ }
160
+
161
+ interface UnisatWallet {
162
+ getAccounts(): Promise<string[]>;
163
+ getPublicKey(): Promise<string>;
164
+ signPsbt(psbtHex: string, options?: {
165
+ autoFinalized?: boolean;
166
+ }): Promise<string>;
167
+ signMessage(message: string, type?: 'bip322-simple' | 'ecdsa'): Promise<string>;
168
+ requestAccounts(): Promise<string[]>;
169
+ sendBitcoin(address: string, satoshis: number): Promise<string>;
170
+ }
171
+ declare global {
172
+ interface Window {
173
+ unisat?: UnisatWallet;
174
+ }
175
+ }
176
+ declare class UnisatXConnector extends BitcoinXConnector {
177
+ private walletProvider;
178
+ constructor();
179
+ static isAvailable(): boolean;
180
+ get icon(): string;
181
+ connect(): Promise<XAccount | undefined>;
182
+ disconnect(): Promise<void>;
183
+ getWalletProvider(): IBitcoinWalletProvider | undefined;
184
+ recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
185
+ }
186
+
187
+ declare class XverseXConnector extends BitcoinXConnector {
188
+ private walletProvider;
189
+ constructor();
190
+ static isAvailable(): boolean;
191
+ get icon(): string;
192
+ connect(): Promise<XAccount | undefined>;
193
+ disconnect(): Promise<void>;
194
+ getWalletProvider(): IBitcoinWalletProvider | undefined;
195
+ recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
196
+ }
197
+
198
+ interface OKXBitcoinWallet {
199
+ getAccounts(): Promise<string[]>;
200
+ getPublicKey(): Promise<string>;
201
+ signPsbt(psbtHex: string, options?: {
202
+ autoFinalized?: boolean;
203
+ }): Promise<string>;
204
+ signMessage(message: string, type?: 'bip322-simple' | 'ecdsa'): Promise<string>;
205
+ connect(): Promise<{
206
+ address: string;
207
+ publicKey: string;
208
+ }>;
209
+ sendBitcoin(toAddress: string, satoshis: number): Promise<string>;
210
+ }
211
+ declare global {
212
+ interface Window {
213
+ okxwallet?: {
214
+ bitcoin?: OKXBitcoinWallet;
215
+ };
216
+ }
217
+ }
218
+ declare class OKXXConnector extends BitcoinXConnector {
219
+ private walletProvider;
220
+ constructor();
221
+ static isAvailable(): boolean;
222
+ get icon(): string;
223
+ connect(): Promise<XAccount | undefined>;
224
+ disconnect(): Promise<void>;
225
+ getWalletProvider(): IBitcoinWalletProvider | undefined;
226
+ recreateWalletProvider(xAccount: XAccount): IBitcoinWalletProvider | undefined;
227
+ }
228
+
229
+ /**
230
+ * Hook to return available Bitcoin wallet connectors from the globally registered xService.
231
+ */
232
+ declare function useBitcoinXConnectors(): BitcoinXConnector[];
233
+
131
234
  /**
132
235
  * Service class for handling EVM chain interactions.
133
236
  * Implements singleton pattern and provides methods for wallet/chain operations.
@@ -202,7 +305,6 @@ declare class SolanaXService extends XService {
202
305
  private static instance;
203
306
  connection: Connection | undefined;
204
307
  wallet: WalletContextState | undefined;
205
- provider: AnchorProvider | undefined;
206
308
  private constructor();
207
309
  static getInstance(): SolanaXService;
208
310
  getBalance(address: string | undefined, xToken: XToken): Promise<bigint>;
@@ -273,7 +375,7 @@ declare class SuiXConnector extends XConnector {
273
375
 
274
376
  declare function useXAccount(chainIdentifier?: ChainType | ChainId): XAccount;
275
377
 
276
- declare function useXAccounts(): Partial<Record<"ICON" | "EVM" | "INJECTIVE" | "SUI" | "STELLAR" | "SOLANA" | "NEAR", XAccount>>;
378
+ declare function useXAccounts(): Partial<Record<"ICON" | "EVM" | "INJECTIVE" | "SUI" | "STELLAR" | "SOLANA" | "NEAR" | "BITCOIN", XAccount>>;
277
379
 
278
380
  /**
279
381
  * Hook for connecting to various blockchain wallets across different chains
@@ -427,7 +529,7 @@ declare const useEvmSwitchChain: (expectedXChainId: ChainId) => UseEvmSwitchChai
427
529
  * const walletProvider = useWalletProvider('sui');
428
530
  * ```
429
531
  */
430
- declare function useWalletProvider(spokeChainId: ChainId | undefined): IEvmWalletProvider | ISuiWalletProvider | IIconWalletProvider | IInjectiveWalletProvider | IStellarWalletProvider | ISolanaWalletProvider | INearWalletProvider | undefined;
532
+ declare function useWalletProvider(spokeChainId: ChainId | undefined): IEvmWalletProvider | ISuiWalletProvider | IIconWalletProvider | IInjectiveWalletProvider | IStellarWalletProvider | ISolanaWalletProvider | IBitcoinWalletProvider | INearWalletProvider | undefined;
431
533
 
432
534
  type SignMessageReturnType = `0x${string}` | Uint8Array | string | undefined;
433
535
  declare function useXSignMessage(): UseMutationResult<SignMessageReturnType, Error, {
@@ -466,4 +568,4 @@ declare const SodaxWalletProvider: ({ children, rpcConfig }: {
466
568
  rpcConfig: RpcConfig;
467
569
  }) => React.JSX.Element;
468
570
 
469
- export { type CurrencyKey, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService, SodaxWalletProvider, SolanaXConnector, SolanaXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, WalletId, type XAccount, type XConnection, XConnector, XService, getWagmiChainId, getXChainType, getXService, isNativeToken, switchEthereumChain, useEvmSwitchChain, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };
571
+ export { BitcoinXConnector, BitcoinXService, type CurrencyKey, EvmXConnector, EvmXService, IconHanaXConnector, IconXService, InjectiveKelprXConnector, InjectiveMetamaskXConnector, InjectiveXService, OKXXConnector, SodaxWalletProvider, SolanaXConnector, SolanaXService, StellarWalletsKitXConnector, StellarXService, SuiXConnector, SuiXService, UnisatXConnector, WalletId, type XAccount, type XConnection, XConnector, XService, XverseXConnector, getWagmiChainId, getXChainType, getXService, isNativeToken, switchEthereumChain, useBitcoinXConnectors, useEvmSwitchChain, useWalletProvider, useXAccount, useXAccounts, useXBalances, useXConnect, useXConnection, useXConnectors, useXDisconnect, useXService, useXSignMessage, useXWagmiStore };