-
Notifications
You must be signed in to change notification settings - Fork 1
/
provider.ts
95 lines (76 loc) · 2.45 KB
/
provider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import type { TransactionRequest } from '@ethersproject/abstract-provider'
import type { Deferrable } from '@ethersproject/properties'
import type {
Transaction as SolTransaction,
TransactionSignature,
} from '@solana/web3.js'
import type { providers } from 'ethers'
import type { CHAIN_TYPES, PROVIDERS } from '@/enums'
import type { WalletConnectInitArgs } from '@/types'
import type { Chain, ChainId } from './chain'
import type { EthereumProvider } from './ethereum'
import type {
NearRawProvider,
NearTransactionResponse,
NearTxRequestBody,
} from './near'
import type {
ProviderListeners,
ProviderSubscriber,
} from './provider-event-bus'
import type { SolanaProvider } from './solana'
export type RawProvider =
| EthereumProvider
| SolanaProvider
| NearRawProvider
| WalletConnectInitArgs
export type ProviderInstance<T extends keyof Record<string, string> = never> = {
name: T | PROVIDERS
instance?: RawProvider
}
export type ProviderConstructorMap = {
[key in PROVIDERS]?: ProviderProxyConstructor
}
export type TxRequestBody =
| Deferrable<TransactionRequest>
| SolTransaction
| NearTxRequestBody
| string
export type EthTransactionResponse = providers.TransactionReceipt
export type SolanaTransactionResponse = TransactionSignature
export type TransactionResponse =
| EthTransactionResponse
| SolanaTransactionResponse
| NearTransactionResponse
export interface ProviderBase {
chainId?: ChainId
chainType?: CHAIN_TYPES
address?: string
rawProvider?: RawProvider
isConnected: boolean
connect?: () => Promise<void>
addChain?: (chain: Chain) => Promise<void>
switchChain?: (chainId: ChainId) => Promise<void>
signAndSendTx?: (txRequestBody: TxRequestBody) => Promise<TransactionResponse>
signMessage?: (message: string) => Promise<string>
getHashFromTx?: (txResponse: TransactionResponse) => string
getTxUrl?: (chain: Chain, txHash: string) => string
getAddressUrl?: (chain: Chain, address: string) => string
disconnect?: () => Promise<void>
}
export interface ProviderProxy extends ProviderBase, ProviderSubscriber {
init: () => Promise<void>
}
export interface IProvider extends ProviderBase, ProviderSubscriber {
providerType?: string
init: (
provider: ProviderInstance,
listeners?: ProviderListeners,
) => Promise<this>
connect: () => Promise<void>
chainDetails?: Chain
}
export interface ProviderProxyConstructor {
new (provider: RawProvider): ProviderProxy
providerType: string
}