Skip to content

Commit

Permalink
convert address to checksum when reading from contract method
Browse files Browse the repository at this point in the history
  • Loading branch information
tom2drum committed Jul 11, 2024
1 parent 7f6b89c commit 0c82ce1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ui/address/contract/methods/useCallMethodPublicClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { getAddress } from 'viem';
import { usePublicClient } from 'wagmi';

import type { FormSubmitResult, MethodCallStrategy, SmartContractMethod } from './types';
Expand All @@ -15,7 +16,7 @@ interface Params {

export default function useCallMethodPublicClient(): (params: Params) => Promise<FormSubmitResult> {
const publicClient = usePublicClient({ chainId: Number(config.chain.id) });
const { address } = useAccount();
const { address: account } = useAccount();

return React.useCallback(async({ args, item, addressHash, strategy }) => {
if (!('name' in item)) {
Expand All @@ -26,12 +27,14 @@ export default function useCallMethodPublicClient(): (params: Params) => Promise
throw new Error('Public Client is not defined');
}

const address = getAddress(addressHash);

const params = {
abi: [ item ],
functionName: item.name,
args: args,
address: addressHash as `0x${ string }`,
account: address,
address,
account,
};

const result = strategy === 'read' ? await publicClient.readContract(params) : await publicClient.simulateContract(params);
Expand All @@ -40,5 +43,5 @@ export default function useCallMethodPublicClient(): (params: Params) => Promise
data: strategy === 'read' ? result : result.result,
};

}, [ address, publicClient ]);
}, [ account, publicClient ]);
}

0 comments on commit 0c82ce1

Please sign in to comment.