forked from tahowallet/extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtally-provider.ts
47 lines (43 loc) · 1.46 KB
/
tally-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
import { Deferrable } from "@ethersproject/properties"
import {
JsonRpcSigner,
TransactionRequest,
TransactionResponse,
Web3Provider,
} from "@ethersproject/providers"
import { AccessList } from "@ethersproject/transactions"
import { encodeJSON } from "./lib/utils"
import { toHexChainID, EVMNetwork } from "./networks"
import { TransactionAnnotation } from "./services/enrichment"
interface TallyInternalJsonRpcSigner extends JsonRpcSigner {
sendTransaction(
transaction: Deferrable<
TransactionRequest & { annotation?: TransactionAnnotation }
>,
): Promise<TransactionResponse>
}
// Not sure the best place to put this in but it feels like it deserves its own file.
export default class TallyWeb3Provider extends Web3Provider {
switchChain(network: EVMNetwork): Promise<unknown> {
return this.send("wallet_switchEthereumChain", [
{
chainId: toHexChainID(network.chainID),
},
])
}
override getSigner(
addressOrIndex?: string | number,
): TallyInternalJsonRpcSigner {
return super.getSigner(addressOrIndex)
}
static override hexlifyTransaction(
transaction: TransactionRequest & { annotation?: TransactionAnnotation },
allowExtra?: { [key: string]: boolean },
): { [key: string]: string | AccessList } {
const { annotation, ...transactionRequest } = transaction
return {
...Web3Provider.hexlifyTransaction(transactionRequest, allowExtra),
annotation: encodeJSON(annotation),
}
}
}