diff --git a/src/Wallets.tsx b/src/Wallets.tsx index 1de70d6..f0933a8 100644 --- a/src/Wallets.tsx +++ b/src/Wallets.tsx @@ -20,9 +20,8 @@ const parsefilenameQortal = (filename)=> { export const Wallets = ({ setExtState, setRawWallet, rawWallet }) => { const [wallets, setWallets] = useState([]); - const [isLoading, setIsLoading] = useState(false); + const [isLoading, setIsLoading] = useState(true); - const hasFetchedWalletsRef = useRef(false) const { getRootProps, getInputProps } = useDropzone({ accept: { "application/json": [".json"], // Only accept JSON files @@ -100,7 +99,7 @@ export const Wallets = ({ setExtState, setRawWallet, rawWallet }) => { useEffect(()=> { setIsLoading(true) getWallets().then((res)=> { - hasFetchedWalletsRef.current = true + if(res && Array.isArray(res)){ setWallets(res) } @@ -112,10 +111,10 @@ export const Wallets = ({ setExtState, setRawWallet, rawWallet }) => { }, []) useEffect(()=> { - if(hasFetchedWalletsRef.current && wallets && Array.isArray(wallets)){ + if(!isLoading && wallets && Array.isArray(wallets)){ storeWallets(wallets) } - }, [wallets]) + }, [wallets, isLoading]) if(isLoading) return null diff --git a/src/background.ts b/src/background.ts index 75951f7..c8f33b0 100644 --- a/src/background.ts +++ b/src/background.ts @@ -856,14 +856,14 @@ export async function getWallets() { if (res) { return res; } else { - throw new Error("No wallet saved"); + return null } } export async function storeWallets(wallets) { storeData("wallets", wallets) .catch((error) => { - reject(new Error(error.message || "Error saving data")); + console.error(error) }); }