Skip to content
This repository was archived by the owner on Oct 27, 2023. It is now read-only.
Merged
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
13 changes: 8 additions & 5 deletions contexts/network-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const NetworkSettingsProvider = ({ children }) => {
referred to user nework when he access `/my-network` page from/in another network.
*/
const [forcedNetwork, setForcedNetwork] = useState<Network>();
const [networkSettings, setNetworkSettings] = useState(DefaultNetworkSettings)
const [networkSettings, setNetworkSettings] = useState(JSON.parse(JSON.stringify(DefaultNetworkSettings)))
const [isLoadingData, setIsLoadingData] = useState(false);
const [registryToken, setRegistryToken] = useState<Token>();

Expand All @@ -60,6 +60,7 @@ export const NetworkSettingsProvider = ({ children }) => {

const isCreating = useMemo(() => ["/new-network", "/setup"].includes(router.pathname), [router.pathname]);
const needsToLoad = useMemo(() => ALLOWED_PATHS.includes(router.pathname), [router.pathname]);
const isSetup = useMemo(() => router.pathname === "/setup", [router.pathname]);
const network =
useMemo(() =>
forcedNetwork || state.Service?.network?.active, [forcedNetwork, state.Service?.network?.active]);
Expand Down Expand Up @@ -210,7 +211,7 @@ export const NetworkSettingsProvider = ({ children }) => {
validator: async (value: string) => {
let validated = undefined;

if (value.trim() !== "")
if (value.trim() !== "" && !isSetup)
validated = /bepro|taikai/gi.test(value) ? false : !(await getNetwork({name: value}).catch(() => false));

return !!validated;
Expand Down Expand Up @@ -357,7 +358,7 @@ export const NetworkSettingsProvider = ({ children }) => {
}

async function loadDefaultSettings(): Promise<typeof DefaultNetworkSettings>{
const defaultState = DefaultNetworkSettings;
const defaultState = JSON.parse(JSON.stringify(DefaultNetworkSettings)); //Deep Copy, More: https://www.codingem.com/javascript-clone-object

const balance = await getTokenBalance();

Expand Down Expand Up @@ -397,7 +398,8 @@ export const NetworkSettingsProvider = ({ children }) => {

if(storageData){
if(storageData?.details){
defaultState.details.name = storageData?.details.name;
const nameValue = storageData?.details.name.value;
defaultState.details.name = {value: nameValue, validated: await Fields.name.validator(nameValue)};
defaultState.details.description = storageData?.details.description;
}

Expand All @@ -416,7 +418,8 @@ export const NetworkSettingsProvider = ({ children }) => {
}

async function loadNetworkSettings(): Promise<typeof DefaultNetworkSettings>{
const defaultState = DefaultNetworkSettings;
const defaultState = JSON.parse(JSON.stringify(DefaultNetworkSettings)); //Deep Copy, More: https://www.codingem.com/javascript-clone-object

const service = await loadDaoService()
const [
treasury,
Expand Down