Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 54 additions & 7 deletions src/components/transactions/eip5792/sendCalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ export const DEFAULT_CALLS = [

const ERC20_USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
const ERC20_USDT = '0xdAC17F958D2ee523a2206206994597C13D831ec7';
const CHAIN_ID_MAINNET = 1;
const REQUIRED_AMOUNT = '0x186a0'; // 0.1 USDC (100000 units, 6 decimals)
const ERC721_BORED_APE = '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d';
const ERC1155_OPENSTORE = '0x495f947276749ce646f68ac8c248420045cb7b5e';
const PERMIT2 = '0x000000000022D473030F116dDEE9F6B43aC78BA3';
const TEST_RECIPIENT_ADDRESS = '0x0c54FcCd2e384b4BB6f2E405Bf5Cbc15a017AaFb';

const CALL_APPROVAL_ERC20_LEGACY = {
data: '0x095ea7b30000000000000000000000000c54FcCd2e384b4BB6f2E405Bf5Cbc15a017AaFb0000000000000000000000000000000000000000000000000000000000459480',
Expand Down Expand Up @@ -112,6 +115,14 @@ export function sendCallsComponent(parentContainer) {
Send Calls - Multiple Approvals
</button>

<button
class="btn btn-primary btn-lg btn-block mb-3"
id="eip5792SendCallsRequiredAssetsButton"
disabled
>
Send Calls - Required Assets
</button>

<p class="info-text alert alert-warning" id="eip5792SendCallsErrorContainer" hidden>
<span class="wrap" id="eip5792SendCallsError"></span>
</p>`,
Expand All @@ -128,25 +139,41 @@ export function sendCallsComponent(parentContainer) {
const sendCallsApprovalButton = document.getElementById(
'eip5792SendCallsApprovalButton',
);
const sendCallsRequiredAssetsButton = document.getElementById(
'eip5792SendCallsRequiredAssetsButton',
);
const errorContainer = document.getElementById(
'eip5792SendCallsErrorContainer',
);
const errorOutput = document.getElementById('eip5792SendCallsError');

function updateRequiredAssetsButtonState() {
const isConnected =
globalContext.accounts && globalContext.accounts.length > 0;
const isMainnet = globalContext.chainIdInt === CHAIN_ID_MAINNET;
sendCallsRequiredAssetsButton.disabled = !isConnected || !isMainnet;
}

document.addEventListener('globalConnectionChange', function (e) {
if (e.detail.connected) {
editButton.disabled = false;
addCallButton.disabled = false;
sendCallsButton.disabled = false;
sendCallsApprovalButton.disabled = false;
updateRequiredAssetsButtonState();
}
});

document.addEventListener('chainChanged', function () {
updateRequiredAssetsButtonState();
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chain change listener uses wrong event name

Medium Severity

The event listener registers for chainChanged on document, but this event is never dispatched there. When the chain changes, the Ethereum provider emits chainChanged, and the app's index.js handles this by dispatching newChainIdInt on document. Other components like batchUsdcSwap.js correctly listen for newChainIdInt. Because of this, updateRequiredAssetsButtonState() won't be called when users switch networks, leaving the button in an incorrect enabled/disabled state.

Fix in Cursor Fix in Web


document.addEventListener('disableAndClear', function () {
editButton.disabled = true;
addCallButton.disabled = true;
sendCallsButton.disabled = true;
sendCallsApprovalButton.disabled = true;
sendCallsRequiredAssetsButton.disabled = true;
});

editButton.onclick = async () => {
Expand Down Expand Up @@ -191,16 +218,36 @@ export function sendCallsComponent(parentContainer) {
]);
};

async function submitRequest(calls) {
try {
const result = await globalContext.provider.request({
method: 'wallet_sendCalls',
params: [
sendCallsRequiredAssetsButton.onclick = () => {
submitRequest([{ to: TEST_RECIPIENT_ADDRESS, value: '0x0' }], {
auxiliaryFunds: {
supported: true,
requiredAssets: [
{
...getParams(),
...(calls ? { calls } : {}),
address: ERC20_USDC,
amount: REQUIRED_AMOUNT,
standard: 'erc20',
},
],
},
});
};

async function submitRequest(calls, capabilities) {
try {
const params = getParams();

if (calls) {
params.calls = calls;
}

if (capabilities) {
params.capabilities = capabilities;
}

const result = await globalContext.provider.request({
method: 'wallet_sendCalls',
params: [params],
});

document.getElementById('eip5792RequestIdInput').value = result.id;
Expand Down
Loading