diff --git a/src/components/beet/BeetLink.jsx b/src/components/beet/BeetLink.jsx index 3d61bee..10001ec 100644 --- a/src/components/beet/BeetLink.jsx +++ b/src/components/beet/BeetLink.jsx @@ -10,15 +10,11 @@ import { appStore, beetStore, identitiesStore } from '../../lib/states'; export default function BeetLink(properties) { const { t, i18n } = useTranslation(); const environment = appStore((state) => state.environment); - const setMode = appStore((state) => state.setMode); const link = beetStore((state) => state.link); const setConnection = beetStore((state) => state.setConnection); const setAuthenticated = beetStore((state) => state.setAuthenticated); - const identity = beetStore((state) => state.identity); - const setIdentities = identitiesStore((state) => state.setIdentities); - const [inProgress, setInProgress] = useState(false); /* * After connection attempt to link app to Beet client diff --git a/src/components/beet/GetAccount.jsx b/src/components/beet/GetAccount.jsx index fbc3a13..9d9801a 100644 --- a/src/components/beet/GetAccount.jsx +++ b/src/components/beet/GetAccount.jsx @@ -50,10 +50,6 @@ export default function GetAccount(properties) { assetName = "TEST"; relevantChain = 'BTS_TEST'; titleName = "Bitshares (Testnet)"; - } else if (env === 'tusc' || params.env === 'tusc') { - assetName = "TUSC"; - relevantChain = 'TUSC'; - titleName = "TUSC"; } useEffect(() => { diff --git a/src/lib/states.js b/src/lib/states.js index d326257..3e7e5f6 100644 --- a/src/lib/states.js +++ b/src/lib/states.js @@ -121,60 +121,90 @@ const identitiesStore = create( ); /** - * NFT_Viewer related + * Global app settings */ -const appStore = create((set, get) => ({ - nodes: { - bitshares: config.bitshares.nodeList.map((node) => node.url), - bitshares_testnet: config.bitshares_testnet.nodeList.map((node) => node.url), - tusc: config.tusc.nodeList.map((node) => node.url), - }, - environment: null, - setEnvironment: (env) => set({ environment: env }), - replaceNodes: (env, nodes) => { - if (env === 'bitshares') { - set(async (state) => ({ - nodes: { ...state.nodes, bitshares: nodes }, - })); - } else if (env === 'bitshares_testnet') { - set(async (state) => ({ - nodes: { ...state.nodes, bitshares_testnet: nodes }, - })); - } else if (env === 'tusc') { - set(async (state) => ({ - nodes: { ...state.nodes, tusc: nodes }, - })); - } - }, - changeURL: (env) => { - /** - * The current node url isn't healthy anymore - * shift it to the back of the queue - * Replaces nodeFailureCallback - */ - console.log('Changing primary node'); - const nodesToChange = get().nodes[env]; - nodesToChange.push(nodesToChange.shift()); // Moving misbehaving node to end - - if (env === 'bitshares') { - set(async (state) => ({ - nodes: { ...state.nodes, bitshares: nodesToChange }, - })); - } else if (env === 'bitshares_testnet') { - set(async (state) => ({ - nodes: { ...state.nodes, bitshares_testnet: nodesToChange }, - })); - } else if (env === 'tusc') { - set(async (state) => ({ - nodes: { ...state.nodes, tusc: nodesToChange }, - })); - } - }, - reset: () => set({ - environment: null, - nodes: null, - }), -})); +const appStore = create( + persist( + (set, get) => ({ + environment: null, + nodes: { + bitshares: config.bitshares.nodeList.map((node) => node.url), + bitshares_testnet: config.bitshares_testnet.nodeList.map((node) => node.url), + }, + setEnvironment: (env) => set({ environment: env }), + setNodes: async () => { + const env = get().environment; + if (!env) { + console.log('No env set'); + return; + } + + let response; + try { + response = await testNodes(env === 'production' ? 'BTS' : 'BTS_TEST'); + } catch (error) { + console.log(error); + } + + if (response) { + set({ nodes: await response }); + } + }, + changeURL: (env) => { + /** + * The current node url isn't healthy anymore + * shift it to the back of the queue + * Replaces nodeFailureCallback + */ + console.log('Changing primary node'); + const nodesToChange = get().nodes[env]; + nodesToChange.push(nodesToChange.shift()); // Moving misbehaving node to end + + if (env === 'bitshares') { + set(async (state) => ({ + nodes: { ...state.nodes, bitshares: nodesToChange }, + })); + } else if (env === 'bitshares_testnet') { + set(async (state) => ({ + nodes: { ...state.nodes, bitshares_testnet: nodesToChange }, + })); + } else if (env === 'tusc') { + set(async (state) => ({ + nodes: { ...state.nodes, tusc: nodesToChange }, + })); + } + }, + removeURL: (env, url) => { + let nodesToChange = get().nodes[env]; + nodesToChange = nodesToChange.filter((x) => x !== url); + + if (env === 'bitshares') { + set((state) => ({ + nodes: { ...state.nodes, bitshares: nodesToChange }, + })); + } else if (env === 'bitshares_testnet') { + set((state) => ({ + nodes: { ...state.nodes, bitshares_testnet: nodesToChange }, + })); + } else if (env === 'tusc') { + set((state) => ({ + nodes: { ...state.nodes, tusc: nodesToChange }, + })); + } + }, + reset: () => set({ + environment: null, + nodes: { + bitshares: config.bitshares.nodeList.map((node) => node.url), + bitshares_testnet: config.bitshares_testnet.nodeList.map((node) => node.url), + }, + }), + }), + { + name: 'nodeStorage', + }, + ), +); /** * Temporary store for the NFT Issuance Tool @@ -183,6 +213,7 @@ const tempStore = create( (set, get) => ({ account: "", asset: null, + assets: null, asset_images: null, initialValues: null, changing_images: false,