From c92efa46ce935fb784b94e27c30c6509e63c63ef Mon Sep 17 00:00:00 2001 From: Dinesh Date: Tue, 7 Feb 2023 12:07:41 +0530 Subject: [PATCH] added arcana --- frontend/pages/_app.tsx | 8 +------- frontend/pages/index.tsx | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/frontend/pages/_app.tsx b/frontend/pages/_app.tsx index 7625fad..e4f319c 100644 --- a/frontend/pages/_app.tsx +++ b/frontend/pages/_app.tsx @@ -7,13 +7,7 @@ import { ProvideAuth } from "@arcana/auth-react"; const arcanaProvider = new AuthProvider( "56639397ce14b62124c30a0679cc4642b1486386", { - position: "left", // defaults to right - theme: "light", // defaults to dark - alwaysVisible: true, // defaults to true which is Full UI mode - chainConfig: { - chainId: "0x1", - rpcUrl: "https://rpc.testnet.mantle.xyz ", - }, + alwaysVisible: true, } ); diff --git a/frontend/pages/index.tsx b/frontend/pages/index.tsx index aa30b91..7c8afff 100644 --- a/frontend/pages/index.tsx +++ b/frontend/pages/index.tsx @@ -7,9 +7,40 @@ import { Auth, useAuth } from "@arcana/auth-react"; export default function Home() { const auth = useAuth(); + const provider = auth.provider; + console.log(provider, "provider"); const onLogin = async () => { - // Route to authenticated page - await auth.connect(); + const provider = auth.provider; + try { + await auth.connect(); + console.log(provider, "provider"); + const chainId = 1; + console.log(chainId, "chainId"); + await provider.request({ + method: "wallet_switchEthereumChain", + params: [{ chainId: "0x5001" }], + }); + } catch (e) { + if (e.code === 4902) { + await provider.request({ + method: "wallet_addEthereumChain", + params: [ + { + chainId: "0x5001", + chainName: "Mantle Testnet", + rpcUrls: ["https://rpc.testnet.mantle.xyz "], + nativeCurrency: { + name: "Mantle", + symbol: "BIT", + decimals: 18, + }, + blockExplorerUrls: ["https://explorer.testnet.mantle.xyz/"], + }, + ], + }); + } + console.log(e, "onLogin"); + } }; return ( <>