refactor: use web3Provider.listAccounts()
This commit is contained in:
parent
75354cf87d
commit
154e05afa7
@ -42,7 +42,6 @@ export default function App() {
|
|||||||
const [rpcResult, setRpcResult] = useState<IFormattedRpcResponse | null>();
|
const [rpcResult, setRpcResult] = useState<IFormattedRpcResponse | null>();
|
||||||
|
|
||||||
const [modal, setModal] = useState("");
|
const [modal, setModal] = useState("");
|
||||||
const [selectedChainId, setSelectedChainId] = useState<string>();
|
|
||||||
|
|
||||||
const closeModal = () => setModal("");
|
const closeModal = () => setModal("");
|
||||||
const openPingModal = () => setModal("ping");
|
const openPingModal = () => setModal("ping");
|
||||||
@ -94,8 +93,11 @@ export default function App() {
|
|||||||
if (!web3Provider) {
|
if (!web3Provider) {
|
||||||
throw new Error("web3Provider not connected");
|
throw new Error("web3Provider not connected");
|
||||||
}
|
}
|
||||||
const address = accounts[0];
|
|
||||||
const tx = await formatTestTransaction(selectedChainId + ":" + address);
|
const { chainId } = await web3Provider.getNetwork();
|
||||||
|
const [address] = await web3Provider.listAccounts();
|
||||||
|
|
||||||
|
const tx = await formatTestTransaction("eip155:" + chainId + ":" + address);
|
||||||
|
|
||||||
const signature = await web3Provider.send("eth_signTransaction", [tx]);
|
const signature = await web3Provider.send("eth_signTransaction", [tx]);
|
||||||
return {
|
return {
|
||||||
@ -112,7 +114,7 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
const msg = "hello world";
|
const msg = "hello world";
|
||||||
const hexMsg = encoding.utf8ToHex(msg, true);
|
const hexMsg = encoding.utf8ToHex(msg, true);
|
||||||
const address = accounts[0];
|
const [address] = await web3Provider.listAccounts();
|
||||||
const signature = await web3Provider.send("personal_sign", [hexMsg, address]);
|
const signature = await web3Provider.send("personal_sign", [hexMsg, address]);
|
||||||
const valid = utils.verifyMessage(msg, signature) === address;
|
const valid = utils.verifyMessage(msg, signature) === address;
|
||||||
return {
|
return {
|
||||||
@ -129,7 +131,7 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
const msg = "hello world";
|
const msg = "hello world";
|
||||||
const hexMsg = encoding.utf8ToHex(msg, true);
|
const hexMsg = encoding.utf8ToHex(msg, true);
|
||||||
const address = accounts[0];
|
const [address] = await web3Provider.listAccounts();
|
||||||
const signature = await web3Provider.send("eth_sign", [address, hexMsg]);
|
const signature = await web3Provider.send("eth_sign", [address, hexMsg]);
|
||||||
const valid = utils.verifyMessage(msg, signature) === address;
|
const valid = utils.verifyMessage(msg, signature) === address;
|
||||||
return {
|
return {
|
||||||
@ -179,7 +181,7 @@ export default function App() {
|
|||||||
|
|
||||||
const message = JSON.stringify(typedData);
|
const message = JSON.stringify(typedData);
|
||||||
|
|
||||||
const address = accounts[0];
|
const [address] = await web3Provider.listAccounts();
|
||||||
|
|
||||||
// eth_signTypedData params
|
// eth_signTypedData params
|
||||||
const params = [address, message];
|
const params = [address, message];
|
||||||
@ -239,11 +241,6 @@ export default function App() {
|
|||||||
setLocaleStorageTestnetFlag(nextIsTestnetState);
|
setLocaleStorageTestnetFlag(nextIsTestnetState);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onConnect = (chainId: string) => {
|
|
||||||
setSelectedChainId(chainId);
|
|
||||||
onEnable(chainId);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Renders the appropriate model for the given request that is currently in-flight.
|
// Renders the appropriate model for the given request that is currently in-flight.
|
||||||
const renderModal = () => {
|
const renderModal = () => {
|
||||||
switch (modal) {
|
switch (modal) {
|
||||||
@ -271,7 +268,7 @@ export default function App() {
|
|||||||
<Toggle active={isTestnet} onClick={toggleTestnets} />
|
<Toggle active={isTestnet} onClick={toggleTestnets} />
|
||||||
</SToggleContainer>
|
</SToggleContainer>
|
||||||
{chainOptions.map(chainId => (
|
{chainOptions.map(chainId => (
|
||||||
<Blockchain key={chainId} chainId={chainId} chainData={chainData} onClick={onConnect} />
|
<Blockchain key={chainId} chainId={chainId} chainData={chainData} onClick={onEnable} />
|
||||||
))}
|
))}
|
||||||
</SButtonContainer>
|
</SButtonContainer>
|
||||||
</SLanding>
|
</SLanding>
|
||||||
|
@ -219,6 +219,8 @@ export default function App() {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log(accounts);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SLayout>
|
<SLayout>
|
||||||
<Column maxWidth={1000} spanHeight>
|
<Column maxWidth={1000} spanHeight>
|
||||||
|
@ -170,14 +170,22 @@ export function JsonRpcContextProvider({ children }: { children: ReactNode | Rea
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const result: string = await client!.request({
|
let result = "";
|
||||||
topic: session!.topic,
|
|
||||||
chainId,
|
try {
|
||||||
request: {
|
result = await client!.request({
|
||||||
method: "eth_sendTransaction",
|
topic: session!.topic,
|
||||||
params: [tx],
|
chainId,
|
||||||
},
|
request: {
|
||||||
});
|
method: "eth_sendTransaction",
|
||||||
|
params: [tx],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(result);
|
||||||
|
|
||||||
// format displayed result
|
// format displayed result
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user