import { useWalletConnectModal } from '@walletconnect/modal-react-native';
function createWalletConnectDelegate(provider: any): WalletDelegate {
return {
getAddress: async () => {
const accounts = await provider.request({ method: 'eth_accounts' });
return accounts[0];
},
getChainId: async () => {
const chainId = await provider.request({ method: 'eth_chainId' });
return BigInt(parseInt(chainId, 16));
},
signMessage: async (message) => {
const address = await provider.request({ method: 'eth_accounts' }).then((a: string[]) => a[0]);
return provider.request({
method: 'personal_sign',
params: [message, address],
});
},
signTypedData: async (typedDataJson) => {
const address = await provider.request({ method: 'eth_accounts' }).then((a: string[]) => a[0]);
return provider.request({
method: 'eth_signTypedData_v4',
params: [address, typedDataJson],
});
},
sendTransaction: async (to, value, data) => {
const address = await provider.request({ method: 'eth_accounts' }).then((a: string[]) => a[0]);
return provider.request({
method: 'eth_sendTransaction',
params: [{ from: address, to, value: '0x' + BigInt(value).toString(16), data }],
});
},
waitForTransactionReceipt: async (txHash) => {
while (true) {
const receipt = await provider.request({
method: 'eth_getTransactionReceipt',
params: [txHash],
});
if (receipt) {
return {
txHash,
status: receipt.status === '0x1',
logs: receipt.logs.map((log: any) => ({
address: log.address,
topics: log.topics,
data: log.data,
})),
};
}
await new Promise((resolve) => setTimeout(resolve, 1_000));
}
},
};
}