-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into refactor/distributed-metadata
- Loading branch information
Showing
37 changed files
with
1,932 additions
and
677 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@talismn/scale": patch | ||
--- | ||
|
||
fix: workaround for devices with no wasm simd support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
apps/extension/src/ui/domains/Settings/ManageNetworks/NetworkForm/Ethereum/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { EvmNetworkId } from "@talismn/chaindata-provider" | ||
import { ethers } from "ethers" | ||
|
||
// because of validation the same query is done 3 times minimum per url, make all await same promise | ||
const rpcChainIdCache = new Map<string, Promise<EvmNetworkId | null>>() | ||
|
||
export const getEvmRpcChainId = (rpcUrl: string): Promise<string | null> => { | ||
// check if valid url | ||
if (!rpcUrl || !/^https?:\/\/.+$/.test(rpcUrl)) return Promise.resolve(null) | ||
|
||
const cached = rpcChainIdCache.get(rpcUrl) | ||
if (cached) return cached | ||
|
||
const provider = new ethers.providers.StaticJsonRpcProvider(rpcUrl) | ||
const request = provider | ||
.send("eth_chainId", []) | ||
.then((hexChainId) => String(parseInt(hexChainId, 16))) | ||
.catch(() => null) | ||
rpcChainIdCache.set(rpcUrl, request) | ||
|
||
return request | ||
} |
77 changes: 77 additions & 0 deletions
77
apps/extension/src/ui/domains/Settings/ManageNetworks/NetworkForm/Ethereum/schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import i18next from "@core/i18nConfig" | ||
import * as yup from "yup" | ||
|
||
import { getEvmRpcChainId } from "./helpers" | ||
|
||
export const evmNetworkFormSchema = yup | ||
.object({ | ||
id: yup.string().required(""), | ||
isTestnet: yup.boolean().required(), | ||
name: yup.string().required(i18next.t("Required")), | ||
tokenSymbol: yup | ||
.string() | ||
.trim() | ||
.required(i18next.t("Required")) | ||
.min(2, i18next.t("2-6 characters")) | ||
.max(6, i18next.t("2-6 characters")), | ||
tokenDecimals: yup | ||
.number() | ||
.typeError(i18next.t("Must be a number")) | ||
.required(i18next.t("Required")) | ||
.integer(i18next.t("Must be a number")), | ||
blockExplorerUrl: yup.string().url(i18next.t("Invalid URL")), | ||
rpcs: yup | ||
.array() | ||
.of( | ||
yup | ||
.object({ url: yup.string().trim().required(i18next.t("Required")) }) | ||
.test( | ||
"rpc-valid", | ||
i18next.t("Chain ID mismatch"), | ||
async function (rpc, { path, options, createError }) { | ||
if (!rpc || !rpc.url) return true | ||
let targetId = options.context?.evmNetworkId as string | undefined | ||
try { | ||
const chainId = await getEvmRpcChainId(rpc.url) | ||
if (!chainId) | ||
return createError({ | ||
message: i18next.t("Failed to connect"), | ||
path: `${path}.url`, | ||
}) | ||
if (!targetId) targetId = chainId | ||
if (chainId !== targetId) | ||
return createError({ | ||
message: i18next.t("Chain ID mismatch"), | ||
path: `${path}.url`, | ||
}) | ||
} catch (error) { | ||
return createError({ | ||
message: i18next.t("Failed to connect"), | ||
path: `${path}.url`, | ||
}) | ||
} | ||
return true | ||
} | ||
) | ||
) | ||
.required(i18next.t("Required")) | ||
.min(1, i18next.t("RPC URL required")) | ||
.test("rpcs-unique", i18next.t("Must be unique"), function (rpcs) { | ||
if (!rpcs?.length) return true | ||
const urls = rpcs.map((rpc) => rpc.url) | ||
const duplicate = urls.filter((url, i) => { | ||
const prevUrls = urls.slice(0, i) | ||
return prevUrls.includes(url) | ||
}) | ||
|
||
if (duplicate.length) { | ||
return this.createError({ | ||
message: i18next.t("Must be unique"), | ||
path: `rpcs[${urls.lastIndexOf(duplicate[0])}].url`, | ||
}) | ||
} | ||
|
||
return true | ||
}), | ||
}) | ||
.required() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.