Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow manually adding custom networks #3481

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion background/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const RuntimeFlag = {
SUPPORT_NFT_SEND: process.env.SUPPORT_NFT_SEND === "true",
SUPPORT_WALLET_CONNECT: process.env.SUPPORT_WALLET_CONNECT === "true",
SUPPORT_SWAP_QUOTE_REFRESH: process.env.SUPPORT_SWAP_QUOTE_REFRESH === "true",
SUPPORT_CUSTOM_NETWORKS: process.env.SUPPORT_CUSTOM_NETWORKS === "true",
SUPPORT_CUSTOM_RPCS: process.env.SUPPORT_CUSTOM_RPCS === "true",
SUPPORT_UNVERIFIED_ASSET: process.env.SUPPORT_UNVERIFIED_ASSET === "true",
ENABLE_UPDATED_DAPP_CONNECTIONS:
Expand Down
17 changes: 15 additions & 2 deletions background/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
} from "./services"

import { HexString, KeyringTypes, NormalizedEVMAddress } from "./types"
import { SignedTransaction } from "./networks"
import { EVMNetwork, SignedTransaction } from "./networks"
import { AccountBalance, AddressOnNetwork, NameOnNetwork } from "./accounts"
import { Eligible } from "./services/doggo/types"

Expand Down Expand Up @@ -138,7 +138,10 @@ import {
migrateReduxState,
REDUX_STATE_VERSION,
} from "./redux-slices/migrations"
import { PermissionMap } from "./services/provider-bridge/utils"
import {
PermissionMap,
ValidatedAddEthereumChainParameter,
} from "./services/provider-bridge/utils"
import { TALLY_INTERNAL_ORIGIN } from "./services/internal-ethereum-provider/constants"
import {
ActivityDetail,
Expand Down Expand Up @@ -1849,6 +1852,16 @@ export default class Main extends BaseService<never> {
)
}

async addCustomNetwork(
networkParams: ValidatedAddEthereumChainParameter
): Promise<EVMNetwork> {
const customNetwork = await this.chainService.addCustomChain(networkParams)

this.store.dispatch(setSelectedNetwork(customNetwork))

return customNetwork
}

async removeEVMNetwork(chainID: string): Promise<void> {
// Per origin chain id settings
await this.internalEthereumProviderService.removePrefererencesForChain(
Expand Down
11 changes: 11 additions & 0 deletions background/redux-slices/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { removeChainBalances } from "./accounts"
import { selectCurrentNetwork } from "./selectors/uiSelectors"
import { setSelectedNetwork } from "./ui"
import { createBackgroundAsyncThunk } from "./utils"
import { ValidatedAddEthereumChainParameter } from "../services/provider-bridge/utils"

type NetworkState = {
blockHeight: number | null
Expand Down Expand Up @@ -95,3 +96,13 @@ export const removeCustomChain = createBackgroundAsyncThunk(
return main.removeEVMNetwork(chainID)
}
)

export const addCustomChain = createBackgroundAsyncThunk(
"networks/addCustomChain",
async (
[network]: [ValidatedAddEthereumChainParameter],
{ extra: { main } }
) => {
return main.addCustomNetwork(network)
}
)
24 changes: 21 additions & 3 deletions ui/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@
}
},
"comingSoon": "Coming soon",
"customNetworksTab": {
"form": {
"title": "Add custom network",
"subtitle": "Make sure you trust the provider and that details are correct.<br>Adding malicious RPC could result in loss of funds.<br>If you aren't sure of the details of an RPC, we advice using <url>ChainList</url> to add them.",
"input.networkName": "Network name",
"input.rpc": "RPC URL",
"input.chainID": "Chain ID",
"input.symbol": "Currency Symbol",
"input.blockExplorer": "Block explorer (Optional)",
"input.logoURL": "Link to logo (Optional)",
"input.isTestnet": "This is a test network",
"submit": "Add network"
},
"success": {
"title": "Custom network added!",
"subtitle": "You can open your wallet now and check out your new network!"
}
},
"dappConnection": {
"connectToDapp": "Connect to dApp",
"dappPermissionListTitle": "dApp would get permission to:",
Expand Down Expand Up @@ -603,7 +621,8 @@
"backButtonText": "Back",
"saveBtn": "Save",
"closeWindow": "Close window",
"copyTextSnackbar": "Copied to clipboard"
"copyTextSnackbar": "Copied to clipboard",
"invalidValue": "Invalid value"
},
"signing": {
"signatureRequired": "Your signature is required",
Expand Down Expand Up @@ -946,7 +965,6 @@
"SUPPORT_NFT_SEND": "Enable sending NFTs",
"SUPPORT_ARBITRUM_NOVA": "Enable Arbitrum Nova network",
"SUPPORT_SWAP_QUOTE_REFRESH": "Enable automatic swap quote updates",
"SUPPORT_CUSTOM_NETWORKS": "Show custom network page on settings panel",
"SUPPORT_CUSTOM_RPCS": "Enable adding custom RPCs",
"SUPPORT_UNVERIFIED_ASSET": "Enable assets verification"
}
Expand All @@ -960,4 +978,4 @@
"earn": "Earn",
"settings": "Settings"
}
}
}
Loading