Skip to content

Commit

Permalink
Dynamically update chainid for send calls requests (#1455)
Browse files Browse the repository at this point in the history
  • Loading branch information
wcrozier12 authored Dec 4, 2024
1 parent e6978b8 commit 7af758f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
20 changes: 14 additions & 6 deletions examples/testapp/src/components/RpcMethods/RpcMethodCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { mainnet } from 'viem/chains';

import { useCBWSDK } from '../../context/CBWSDKReactContextProvider';
import { verifySignMsg } from './method/signMessageMethods';
import { ADDR_TO_FILL } from './shortcut/const';
import { ADDR_TO_FILL, CHAIN_ID_TO_FILL } from './shortcut/const';
import { multiChainShortcutsMap } from './shortcut/multipleChainShortcuts';

type ResponseType = string;
Expand Down Expand Up @@ -71,18 +71,26 @@ export function RpcMethodCard({ format, method, params, shortcuts }) {
setVerifyResult(null);
setResponse(null);
if (!provider) return;
let values = data;

const dataToSubmit = { ...data };
let values = dataToSubmit;
if (format) {
// fill active address to the request
const addresses = await provider.request({ method: 'eth_accounts' });
for (const key in data) {
const chainId = await provider.request({ method: 'eth_chainId' });

for (const key in dataToSubmit) {
if (Object.prototype.hasOwnProperty.call(data, key)) {
if (data[key] === ADDR_TO_FILL) {
data[key] = addresses[0];
if (dataToSubmit[key] === ADDR_TO_FILL) {
dataToSubmit[key] = addresses[0];
}

if (dataToSubmit[key] === CHAIN_ID_TO_FILL) {
dataToSubmit[key] = chainId;
}
}
}
values = format(data);
values = format(dataToSubmit);
}
try {
const response = await provider.request({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const EXAMPLE_MESSAGE = `Example Message`;

export const ADDR_TO_FILL = 'ADDR_TO_FILL';
export const CHAIN_ID_TO_FILL = 'CHAIN_ID_TO_FILL';
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ADDR_TO_FILL } from './const';
import { ADDR_TO_FILL, CHAIN_ID_TO_FILL } from './const';
import { ShortcutType } from './ShortcutType';

const walletSendCallsShortcuts: ShortcutType[] = [
{
key: 'wallet_sendCalls',
data: {
chainId: '84532',
chainId: CHAIN_ID_TO_FILL,
from: ADDR_TO_FILL,
calls: [],
version: '1',
Expand Down

0 comments on commit 7af758f

Please sign in to comment.