Skip to content

Commit

Permalink
implement provider
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo committed Nov 30, 2022
1 parent b85e25e commit 4162db2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
35 changes: 25 additions & 10 deletions packages/admin-ui/src/pages/dashboard/components/ChainCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { HelpTo } from "components/Help";
import { Link } from "react-router-dom";
import { rootPath as packagesRootPath } from "pages/packages";
import Button from "components/Button";
import { ethers } from "ethers";

export function ChainCards() {
const chainData = useChainData();
Expand Down Expand Up @@ -54,6 +55,16 @@ function ChainCard(chain: ChainData) {
<>
<ProgressBar now={100} variant="success" />
{wallet ? <ConnectWallet wallet={wallet} /> : null}
{dnpName === "nethermind-xdai.dnp.dappnode.eth" && (
<ConnectWallet
wallet={{
chainId: "0x64",
chainName: "Gnosis chain",
nativeCurrency: { name: "Gosis", symbol: "GNO", decimals: 18 },
rpcUrls: ["https://rpc.gnosischain.com"]
}}
/>
)}
</>
)}

Expand All @@ -75,29 +86,33 @@ declare global {

function ConnectWallet({ wallet }: { wallet: Wallet }) {
async function walletConnect() {
const provider = new ethers.providers.Web3Provider(window.ethereum);
console.log("provider: ", provider);
try {
console.log("trying..");

// https://eips.ethereum.org/EIPS/eip-3326
await window.ethereum.request({
method: "wallet_switchEthereumChain",
params: [{ chainId: wallet.chainId }]
});
await provider.send("wallet_switchEthereumChain", [
{ chainId: wallet.chainId }
]);
console.log("failed");
} catch (switchError) {
console.error(switchError);
// This error code indicates that the chain has not been added to MetaMask.
if (switchError.code === 4902) {
try {
// https://eips.ethereum.org/EIPS/eip-3085
await window.ethereum.request({
method: "wallet_addEthereumChain",
await provider.send(
"wallet_addEthereumChain",
// IMPORTANT! RPC without HTTPs is not allowed
// IMPORTANT! Add new chains with a default chain ID in metamask is not allowed
params: [
// IMPORTANT! Add new chains with a default chain ID in metamask is not allowed family horn own sense negative orient tomorrow cheap recall mutual addict inmate
[
{
chainId: wallet.chainId,
chainName: wallet.chainName,
rpcUrls: [wallet.rpcUrls]
}
]
});
);
} catch (addError) {
// handle "add" error
throw addError;
Expand Down
3 changes: 2 additions & 1 deletion packages/dappmanager/src/modules/compose/labelsDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ const labelStringifyFns: {
"dappnode.dnp.serviceName": writeString,
"dappnode.dnp.instanceName": writeString,
"dappnode.dnp.dependencies": writeJson,
"dappnode.dnp.wallet": writeJson,
"dappnode.dnp.wallet": value =>
writeJson(value as unknown as Record<string, unknown>),
"dappnode.dnp.avatar": writeString,
"dappnode.dnp.origin": writeString,
"dappnode.dnp.chain": value =>
Expand Down

0 comments on commit 4162db2

Please sign in to comment.