-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
142 lines (128 loc) · 3.9 KB
/
index.tsx
File metadata and controls
142 lines (128 loc) · 3.9 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'use client'
import type { Address, Hex } from 'viem'
import { usePendingRequest } from './hooks/usePendingRequest.js'
import { BatchCalls } from './pages/BatchCalls.js'
import { CollectionApproval } from './pages/CollectionApproval.js'
import { Erc20Approval } from './pages/Erc20Approval.js'
import { Erc20Transfer } from './pages/Erc20Transfer.js'
import { EthTransfer } from './pages/EthTransfer.js'
import { GenericRequest } from './pages/GenericRequest.js'
import { PersonalSign } from './pages/PersonalSign.js'
import { SignTypedData } from './pages/SignTypedData.js'
import {
decodeCollectionApproval,
isCollectionApproval,
} from './utils/collectionApproval.js'
import { decodeErc20Approval, isErc20Approval } from './utils/erc20Approval.js'
import { decodeErc20Transfer, isErc20Transfer } from './utils/erc20Transfer.js'
import { isEthTransfer } from './utils/ethTransfer.js'
export function SignatureRequest() {
const { pendingRequest, pendingRequests, confirm, reject } =
usePendingRequest()
if (!pendingRequest) return null
function renderContent() {
switch (pendingRequest.method) {
case 'eth_sendTransaction':
case 'wallet_sendTransaction': {
const tx = pendingRequest.params[0]
if (isEthTransfer(tx)) {
return (
<EthTransfer
to={tx.to as Address}
value={tx.value as Hex}
confirm={confirm}
reject={reject}
/>
)
}
if (isErc20Transfer(tx)) {
const decoded = decodeErc20Transfer(tx)
if (decoded) {
return (
<Erc20Transfer
contract={tx.to as Address}
to={decoded.to}
amount={decoded.amount}
confirm={confirm}
reject={reject}
/>
)
}
}
if (isErc20Approval(tx)) {
const decoded = decodeErc20Approval(tx)
if (decoded) {
return (
<Erc20Approval
contract={tx.to as Address}
spender={decoded.spender}
amount={decoded.amount}
confirm={confirm}
reject={reject}
/>
)
}
}
if (isCollectionApproval(tx)) {
const decoded = decodeCollectionApproval(tx)
if (decoded) {
return (
<CollectionApproval
contract={tx.to as Address}
operator={decoded.operator}
approved={decoded.approved}
confirm={confirm}
reject={reject}
/>
)
}
}
break
}
case 'wallet_sendCalls': {
const { calls } = pendingRequest.params[0]
return <BatchCalls calls={calls} confirm={confirm} reject={reject} />
}
case 'personal_sign': {
const [data, address] = pendingRequest.params
return (
<PersonalSign
data={data}
address={address}
confirm={confirm}
reject={reject}
/>
)
}
case 'eth_signTypedData_v4': {
const [address, typedData] = pendingRequest.params
return (
<SignTypedData
address={address}
typedData={typedData}
confirm={confirm}
reject={reject}
/>
)
}
}
return (
<GenericRequest
request={pendingRequest}
confirm={confirm}
reject={reject}
/>
)
}
return (
<div className="rounded-xl border border-gray-200 bg-white p-6 mt-4 shadow-sm">
{renderContent()}
{pendingRequests.length > 1 && (
<p className="text-xs text-gray-500 mt-3">
+{pendingRequests.length - 1} more pending{' '}
{pendingRequests.length - 1 === 1 ? 'request' : 'requests'}
</p>
)}
</div>
)
}