From 0caa6703db9dd1994532a112d9d9278012e3d232 Mon Sep 17 00:00:00 2001 From: KaffinPX Date: Fri, 2 Aug 2024 00:19:41 +0300 Subject: [PATCH] Add Public Network(Resolver) connection capability ++ new checks on add node menu --- src/contexts/Settings.tsx | 12 ++++++++++-- src/pages/Wallet/Settings/Wallet/Node.tsx | 19 ++++++++++++++----- src/wallet/kaspa/node.ts | 10 ++++++++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/contexts/Settings.tsx b/src/contexts/Settings.tsx index 52ddcd9..9f7a703 100644 --- a/src/contexts/Settings.tsx +++ b/src/contexts/Settings.tsx @@ -20,8 +20,16 @@ export const currencies = { export const defaultSettings: ISettings = { version: 4, nodes: [{ - name: "Kaspa-NG EU", - address: "wss://eu-1.kaspa-ng.io/mainnet", + name: "Public network", + address: "mainnet", + locked: true + }, { + name: "Public network", + address: "testnet-10", + locked: true + }, { + name: "Public network", + address: "testnet-11", locked: true }, { name: "Subsecond.wtf", diff --git a/src/pages/Wallet/Settings/Wallet/Node.tsx b/src/pages/Wallet/Settings/Wallet/Node.tsx index e542b09..f9aed46 100644 --- a/src/pages/Wallet/Settings/Wallet/Node.tsx +++ b/src/pages/Wallet/Settings/Wallet/Node.tsx @@ -1,4 +1,4 @@ -import { useState } from "react" +import { useMemo, useState } from "react" import { i18n } from "webextension-polyfill" import { PlusIcon } from "lucide-react" import { Button } from "@/components/ui/button" @@ -16,10 +16,19 @@ import { Input } from "@/components/ui/input" import useSettings from "@/hooks/useSettings" export default function Export () { + const { settings, updateSetting } = useSettings() + const [ name, setName ] = useState("") const [ address, setAddress ] = useState("") - const { settings, updateSetting } = useSettings() + const addressValid = useMemo(() => { + try { + const parsedUrl = new URL(address) + return parsedUrl.protocol === "ws:" || parsedUrl.protocol === "wss:" + } catch (e) { + return false + } + }, [ address ]) return ( { @@ -46,9 +55,9 @@ export default function Export () {