Skip to content

Commit 78bc9eb

Browse files
feat: add batch approval button (#410)
1 parent a2f6050 commit 78bc9eb

File tree

1 file changed

+77
-2
lines changed

1 file changed

+77
-2
lines changed

src/components/transactions/eip5792/sendCalls.js

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,47 @@ export const DEFAULT_CALLS = [
1515
},
1616
];
1717

18+
const ERC20_USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
19+
const ERC20_USDT = '0xdAC17F958D2ee523a2206206994597C13D831ec7';
20+
const ERC721_BORED_APE = '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d';
21+
const ERC1155_OPENSTORE = '0x495f947276749ce646f68ac8c248420045cb7b5e';
22+
const PERMIT2 = '0x000000000022D473030F116dDEE9F6B43aC78BA3';
23+
24+
const CALL_APPROVAL_ERC20_LEGACY = {
25+
data: '0x095ea7b30000000000000000000000000c54FcCd2e384b4BB6f2E405Bf5Cbc15a017AaFb0000000000000000000000000000000000000000000000000000000000459480',
26+
to: ERC20_USDC,
27+
};
28+
29+
const CALL_APPROVAL_ERC20_PERMIT_2 = {
30+
data: '0x87517c45000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000c54FcCd2e384b4BB6f2E405Bf5Cbc15a017AaFb000000000000000000000000000000000000000000000000000000000012C4B00000000000000000000000000000000000000000000000000000000068437af0',
31+
to: PERMIT2,
32+
};
33+
34+
const CALL_APPROVAL_ERC20_INCREASE_ALLOWANCE = {
35+
data: '0x395093510000000000000000000000000c54FcCd2e384b4BB6f2E405Bf5Cbc15a017AaFb0000000000000000000000000000000000000000000000000000000000786450',
36+
to: ERC20_USDC,
37+
};
38+
39+
const CALL_APPROVAL_ERC20_LEGACY_UNLIMITED = {
40+
data: '0x095ea7b30000000000000000000000000c54FcCd2e384b4BB6f2E405Bf5Cbc15a017AaFb0000000000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFF',
41+
to: ERC20_USDT,
42+
};
43+
44+
const CALL_APPROVAL_ERC721_APPROVE = {
45+
data: '0x095ea7b30000000000000000000000000c54FcCd2e384b4BB6f2E405Bf5Cbc15a017AaFb00000000000000000000000000000000000000000000000000000000000020F0',
46+
to: ERC721_BORED_APE,
47+
};
48+
49+
const CALL_APPROVAL_ERC721_APPROVE_ALL = {
50+
data: '0xa22cb4650000000000000000000000000c54FcCd2e384b4BB6f2E405Bf5Cbc15a017AaFb0000000000000000000000000000000000000000000000000000000000000001',
51+
to: ERC721_BORED_APE,
52+
};
53+
54+
const CALL_APPROVAL_ERC1155_APPROVE_ALL = {
55+
data: '0xa22cb4650000000000000000000000000c54FcCd2e384b4BB6f2E405Bf5Cbc15a017AaFb0000000000000000000000000000000000000000000000000000000000000001',
56+
to: ERC1155_OPENSTORE,
57+
};
58+
1859
export function sendCallsComponent(parentContainer) {
1960
parentContainer.insertAdjacentHTML(
2061
'beforeend',
@@ -63,6 +104,14 @@ export function sendCallsComponent(parentContainer) {
63104
Send Calls
64105
</button>
65106
107+
<button
108+
class="btn btn-primary btn-lg btn-block mb-3"
109+
id="eip5792SendCallsApprovalButton"
110+
disabled
111+
>
112+
Send Calls - Multiple Approvals
113+
</button>
114+
66115
<p class="info-text alert alert-warning" id="eip5792SendCallsErrorContainer" hidden>
67116
<span class="wrap" id="eip5792SendCallsError"></span>
68117
</p>`,
@@ -76,6 +125,9 @@ export function sendCallsComponent(parentContainer) {
76125
const callsContainer = document.getElementById('eip5792Calls');
77126
const addCallButton = document.getElementById('eip5792AddCall');
78127
const sendCallsButton = document.getElementById('eip5792SendCallsButton');
128+
const sendCallsApprovalButton = document.getElementById(
129+
'eip5792SendCallsApprovalButton',
130+
);
79131
const errorContainer = document.getElementById(
80132
'eip5792SendCallsErrorContainer',
81133
);
@@ -86,13 +138,15 @@ export function sendCallsComponent(parentContainer) {
86138
editButton.disabled = false;
87139
addCallButton.disabled = false;
88140
sendCallsButton.disabled = false;
141+
sendCallsApprovalButton.disabled = false;
89142
}
90143
});
91144

92145
document.addEventListener('disableAndClear', function () {
93146
editButton.disabled = true;
94147
addCallButton.disabled = true;
95148
sendCallsButton.disabled = true;
149+
sendCallsApprovalButton.disabled = true;
96150
});
97151

98152
editButton.onclick = async () => {
@@ -122,10 +176,31 @@ export function sendCallsComponent(parentContainer) {
122176
};
123177

124178
sendCallsButton.onclick = async () => {
179+
submitRequest();
180+
};
181+
182+
sendCallsApprovalButton.onclick = () => {
183+
submitRequest([
184+
CALL_APPROVAL_ERC20_LEGACY,
185+
CALL_APPROVAL_ERC20_PERMIT_2,
186+
CALL_APPROVAL_ERC20_INCREASE_ALLOWANCE,
187+
CALL_APPROVAL_ERC20_LEGACY_UNLIMITED,
188+
CALL_APPROVAL_ERC721_APPROVE,
189+
CALL_APPROVAL_ERC721_APPROVE_ALL,
190+
CALL_APPROVAL_ERC1155_APPROVE_ALL,
191+
]);
192+
};
193+
194+
async function submitRequest(calls) {
125195
try {
126196
const result = await globalContext.provider.request({
127197
method: 'wallet_sendCalls',
128-
params: [getParams()],
198+
params: [
199+
{
200+
...getParams(),
201+
...(calls ? { calls } : {}),
202+
},
203+
],
129204
});
130205

131206
document.getElementById('eip5792RequestIdInput').value = result.id;
@@ -136,7 +211,7 @@ export function sendCallsComponent(parentContainer) {
136211
errorContainer.hidden = false;
137212
errorOutput.innerHTML = `Error: ${error.message}`;
138213
}
139-
};
214+
}
140215

141216
function getParams() {
142217
const useInputs = isCustom();

0 commit comments

Comments
 (0)