diff --git a/package.json b/package.json index fcf0e1c..8a8f495 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "web-wallet", - "version": "0.1.7-nym-0.1.2", + "version": "0.1.7-nym-0.1.3", "private": true, "dependencies": { "@cerc-io/registry-sdk": "^0.2.5", diff --git a/src/global.d.ts b/src/global.d.ts index c691cf7..8800b97 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -3,6 +3,15 @@ declare global { interface Window { // Android bridge callbacks for signature and accounts related events Android?: { + // Store a key-value pair securely in encrypted storage + setItem(key: string, value: string): boolean; + + // Retrieve a value by key from encrypted storage + getItem(key: string): string | null; + + // Remove a key-value pair from encrypted storage + removeItem(key: string): boolean; + // Called when signature is successfully generated onSignatureComplete?: (signature: string) => void; diff --git a/src/hooks/useWebViewHandler.ts b/src/hooks/useWebViewHandler.ts index b306a8f..2825764 100644 --- a/src/hooks/useWebViewHandler.ts +++ b/src/hooks/useWebViewHandler.ts @@ -40,12 +40,12 @@ export const useWebViewHandler = () => { try { // Get available networks data const networksData = await retrieveNetworksData(); - + if (!networksData || networksData.length === 0) { window.Android?.onAccountError?.('No networks configured'); return; } - + // Create wallet using the provided mnemonic if it doesn't exist const walletExists = await isWalletCreated(); if (!walletExists) { diff --git a/src/utils/key-store.ts b/src/utils/key-store.ts index f71fdff..f19ba5c 100644 --- a/src/utils/key-store.ts +++ b/src/utils/key-store.ts @@ -1,13 +1,28 @@ const setInternetCredentials = (name:string, username:string, password:string) => { - localStorage.setItem(name, password); + if (window.Android?.setItem) { + window.Android.setItem(name, password); + } else { + localStorage.setItem(name, password); + } }; const getInternetCredentials = (name:string) : string | null => { - return localStorage.getItem(name); + if (window.Android?.getItem) { + const result = window.Android.getItem(name); + + // Normalize undefined to null to match localStorage behavior + return result === undefined ? null : result; + } else { + return localStorage.getItem(name); + } }; const resetInternetCredentials = (name:string) => { - localStorage.removeItem(name); + if (window.Android?.removeItem) { + window.Android.removeItem(name); + } else { + localStorage.removeItem(name); + } }; export {