@reown/appkit-common
Advanced tools
Comparing version 1.0.1 to 1.0.2
export const SafeLocalStorageKeys = { | ||
WALLET_ID: '@w3m/wallet_id', | ||
WALLET_NAME: '@w3m/wallet_name', | ||
SOLANA_WALLET: '@w3m/solana_wallet', | ||
SOLANA_CAIP_CHAIN: '@w3m/solana_caip_chain', | ||
ACTIVE_CAIP_NETWORK: '@w3m/active_caip_network', | ||
ACTIVE_CAIP_NETWORK_ID: '@w3m/active_caip_network_id', | ||
CONNECTED_CONNECTOR: '@w3m/connected_connector' | ||
WALLET_ID: '@appkit/wallet_id', | ||
WALLET_NAME: '@appkit/wallet_name', | ||
SOLANA_WALLET: '@appkit/solana_wallet', | ||
SOLANA_CAIP_CHAIN: '@appkit/solana_caip_chain', | ||
ACTIVE_CAIP_NETWORK: '@appkit/active_caip_network', | ||
ACTIVE_CAIP_NETWORK_ID: '@appkit/active_caip_network_id', | ||
CONNECTED_CONNECTOR: '@appkit/connected_connector', | ||
CONNECTED_SOCIAL: '@appkit/connected_social', | ||
CONNECTED_SOCIAL_USERNAME: '@appkit/connected_social_username', | ||
RECENT_WALLETS: '@appkit/recent_wallets', | ||
DEEPLINK_CHOICE: '@appkit/deeplink_choice' | ||
}; | ||
@@ -23,8 +27,9 @@ export const SafeLocalStorage = { | ||
} | ||
catch { | ||
return null; | ||
catch (e) { | ||
console.warn('Error parsing value from localStorage', key, e); | ||
return undefined; | ||
} | ||
} | ||
} | ||
return null; | ||
return undefined; | ||
}, | ||
@@ -35,2 +40,7 @@ removeItem(key) { | ||
} | ||
}, | ||
clear() { | ||
if (isSafe()) { | ||
localStorage.clear(); | ||
} | ||
} | ||
@@ -37,0 +47,0 @@ }; |
@@ -13,5 +13,5 @@ import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'; | ||
it('should not setItem', () => { | ||
const key = '@w3m/wallet_id'; | ||
const key = '@appkit/wallet_id'; | ||
expect(SafeLocalStorage.setItem(key, '1')).toBe(undefined); | ||
expect(SafeLocalStorage.getItem(key)).toBe(null); | ||
expect(SafeLocalStorage.getItem(key)).toBe(undefined); | ||
expect(SafeLocalStorage.removeItem(key)).toBe(undefined); | ||
@@ -27,15 +27,25 @@ }); | ||
}); | ||
afterAll(() => { | ||
getItem.mockClear(); | ||
setItem.mockClear(); | ||
removeItem.mockClear(); | ||
}); | ||
it('should setItem', () => { | ||
expect(SafeLocalStorage.setItem('@w3m/wallet_id', 'test')).toBe(undefined); | ||
expect(setItem).toHaveBeenCalledWith('@w3m/wallet_id', '"test"'); | ||
expect(SafeLocalStorage.setItem('@appkit/wallet_id', 'test')).toBe(undefined); | ||
expect(setItem).toHaveBeenCalledWith('@appkit/wallet_id', JSON.stringify('test')); | ||
}); | ||
it('should getItem', () => { | ||
expect(SafeLocalStorage.getItem('@w3m/wallet_id')).toEqual({ test: 'test' }); | ||
expect(getItem).toHaveBeenCalledWith('@w3m/wallet_id'); | ||
it('should getItem ', () => { | ||
expect(SafeLocalStorage.getItem('@appkit/wallet_id')).toEqual({ test: 'test' }); | ||
expect(getItem).toHaveBeenCalledWith('@appkit/wallet_id'); | ||
}); | ||
it('should removeItem', () => { | ||
expect(SafeLocalStorage.removeItem('@w3m/wallet_id')).toBe(undefined); | ||
expect(removeItem).toHaveBeenCalledWith('@w3m/wallet_id'); | ||
expect(SafeLocalStorage.removeItem('@appkit/wallet_id')).toBe(undefined); | ||
expect(removeItem).toHaveBeenCalledWith('@appkit/wallet_id'); | ||
}); | ||
it('getItem should return undefined when value is not valid JSON', () => { | ||
getItem.mockReturnValueOnce('test'); | ||
expect(SafeLocalStorage.getItem('@appkit/wallet_id')).toBe(undefined); | ||
expect(getItem).toHaveBeenCalledWith('@appkit/wallet_id'); | ||
}); | ||
}); | ||
//# sourceMappingURL=SafeLocalStorage.test.js.map |
import type { CaipNetwork } from './TypeUtil.js'; | ||
export type SafeLocalStorageItems = { | ||
'@w3m/wallet_id': string; | ||
'@w3m/wallet_name': string; | ||
'@w3m/solana_wallet': string; | ||
'@w3m/solana_caip_chain': string; | ||
'@w3m/active_caip_network': CaipNetwork; | ||
'@w3m/active_caip_network_id': string; | ||
'@w3m/connected_connector': string; | ||
'@appkit/wallet_id': string; | ||
'@appkit/wallet_name': string; | ||
'@appkit/solana_wallet': string; | ||
'@appkit/solana_caip_chain': string; | ||
'@appkit/active_caip_network': CaipNetwork; | ||
'@appkit/active_caip_network_id': string; | ||
'@appkit/connected_connector': string; | ||
'@appkit/connected_social': string; | ||
'@appkit/connected_social_username': string; | ||
'@appkit/recent_wallets': string; | ||
'@appkit/deeplink_choice': { | ||
href: string; | ||
name: string; | ||
}; | ||
}; | ||
export declare const SafeLocalStorageKeys: { | ||
readonly WALLET_ID: "@w3m/wallet_id"; | ||
readonly WALLET_NAME: "@w3m/wallet_name"; | ||
readonly SOLANA_WALLET: "@w3m/solana_wallet"; | ||
readonly SOLANA_CAIP_CHAIN: "@w3m/solana_caip_chain"; | ||
readonly ACTIVE_CAIP_NETWORK: "@w3m/active_caip_network"; | ||
readonly ACTIVE_CAIP_NETWORK_ID: "@w3m/active_caip_network_id"; | ||
readonly CONNECTED_CONNECTOR: "@w3m/connected_connector"; | ||
readonly WALLET_ID: "@appkit/wallet_id"; | ||
readonly WALLET_NAME: "@appkit/wallet_name"; | ||
readonly SOLANA_WALLET: "@appkit/solana_wallet"; | ||
readonly SOLANA_CAIP_CHAIN: "@appkit/solana_caip_chain"; | ||
readonly ACTIVE_CAIP_NETWORK: "@appkit/active_caip_network"; | ||
readonly ACTIVE_CAIP_NETWORK_ID: "@appkit/active_caip_network_id"; | ||
readonly CONNECTED_CONNECTOR: "@appkit/connected_connector"; | ||
readonly CONNECTED_SOCIAL: "@appkit/connected_social"; | ||
readonly CONNECTED_SOCIAL_USERNAME: "@appkit/connected_social_username"; | ||
readonly RECENT_WALLETS: "@appkit/recent_wallets"; | ||
readonly DEEPLINK_CHOICE: "@appkit/deeplink_choice"; | ||
}; | ||
export declare const SafeLocalStorage: { | ||
setItem<Key extends keyof SafeLocalStorageItems>(key: Key, value: SafeLocalStorageItems[Key]): void; | ||
getItem<Key_1 extends keyof SafeLocalStorageItems>(key: Key_1): SafeLocalStorageItems[Key_1] | null; | ||
getItem<Key_1 extends keyof SafeLocalStorageItems>(key: Key_1): SafeLocalStorageItems[Key_1] | undefined; | ||
removeItem<Key_2 extends keyof SafeLocalStorageItems>(key: Key_2): void; | ||
clear(): void; | ||
}; |
{ | ||
"name": "@reown/appkit-common", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"type": "module", | ||
@@ -27,9 +27,9 @@ "main": "./dist/esm/index.js", | ||
"license": "Apache-2.0", | ||
"homepage": "https://github.com/reown-com/appkit", | ||
"homepage": "https://github.com/WalletConnect/web3modal", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/WalletConnect/shadow-appkit.git" | ||
"url": "git+https://github.com/WalletConnect/web3modal.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/reown-com/appkit/issues" | ||
"url": "https://github.com/WalletConnect/web3modal/issues" | ||
}, | ||
@@ -36,0 +36,0 @@ "scripts": { |
@@ -1,2 +0,2 @@ | ||
#### 📚 [Documentation](https://docs.walletconnect.com/2.0/appkit/about) | ||
#### 📚 [Documentation](https://docs.reown.com/2.0/appkit/about) | ||
@@ -3,0 +3,0 @@ #### 🔗 [Website](https://reown.com/appkit) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
124636
1024