mirror of
https://github.com/andrei0x309/clear-wallet.git
synced 2024-12-19 00:00:45 +00:00
add: eth_getCode support
This commit is contained in:
parent
152635b310
commit
b324a6c7ba
@ -56,7 +56,8 @@ const allowedMethods = {
|
||||
'wallet_getPermissions': true,
|
||||
'net_listening': true,
|
||||
'eth_coinbase': true,
|
||||
'wallet_addEthereumChain': true
|
||||
'wallet_addEthereumChain': true,
|
||||
'eth_getCode': true
|
||||
}
|
||||
|
||||
window.addEventListener("message", (event) => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { getSelectedAccount, getSelectedNetwork, smallRandomString, getSettings, clearPk, openTab, getUrl, addToHistory, getNetworks, strToHex } from '@/utils/platform';
|
||||
import { userApprove, userReject, rIdWin, rIdData } from '@/extension/userRequest'
|
||||
import { signMsg, getBalance, getBlockNumber, estimateGas, sendTransaction, getGasPrice, getBlockByNumber, evmCall, getTxByHash, getTxReceipt, signTypedData } from '@/utils/wallet'
|
||||
import { signMsg, getBalance, getBlockNumber, estimateGas, sendTransaction, getGasPrice, getBlockByNumber, evmCall, getTxByHash, getTxReceipt, signTypedData, getCode } from '@/utils/wallet'
|
||||
import type { RequestArguments } from '@/extension/types'
|
||||
import { rpcError } from '@/extension/rpcConstants'
|
||||
import { updatePrices } from '@/utils/gecko'
|
||||
@ -162,6 +162,18 @@ const mainListner = (message: RequestArguments, sender:any, sendResponse: (a: an
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'eth_getCode': {
|
||||
try {
|
||||
sendResponse(await getCode(message?.params?.[0] as string))
|
||||
} catch {
|
||||
sendResponse({
|
||||
error: true,
|
||||
code: rpcError.USER_REJECTED,
|
||||
message: 'No network or user selected'
|
||||
})
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'eth_blockNumber': {
|
||||
try {
|
||||
sendResponse(await getBlockNumber())
|
||||
|
@ -70,6 +70,12 @@ export const getTxReceipt = async (hash: string) => {
|
||||
return await provider.getTransactionReceipt(hash)
|
||||
}
|
||||
|
||||
export const getCode = async (addr: string) => {
|
||||
const network = await getSelectedNetwork()
|
||||
const provider = new ethers.providers.JsonRpcProvider(network.rpc)
|
||||
return await provider.getCode(addr)
|
||||
}
|
||||
|
||||
export const sendTransaction = async ({ data= '', gas='0x0', to='', from='', value='0x0', gasPrice='0x0'}:
|
||||
{to: string, from: string, data: string, value: string, gas: string, gasPrice: string},
|
||||
gasEstimate: Promise<BigNumber> | null = null, pGasPrice : Promise<BigNumber> | null) => {
|
||||
|
Loading…
Reference in New Issue
Block a user