-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #475 from cosmology-tech/fix/supported-chains
don't call experimentalSuggestChain() if it's natively supported
- Loading branch information
Showing
8 changed files
with
229 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
export class ExpiringLocalStorage { | ||
/** | ||
* Add an item to an array in local storage with an expiration time. | ||
* @param {string} key - The key under which the array is stored. | ||
* @param {*} value - The value to be added. | ||
* @param {number} ttl - Time to live in milliseconds. | ||
*/ | ||
static addItem(key, value, ttl) { | ||
const now = new Date(); | ||
|
||
// Create a new item with value and expiry | ||
const newItem = { | ||
value: value, | ||
expiry: now.getTime() + ttl, | ||
}; | ||
|
||
// Get existing items from local storage | ||
const itemStr = localStorage.getItem(key); | ||
const items = itemStr ? JSON.parse(itemStr) : []; | ||
|
||
// Add the new item to the array | ||
items.push(newItem); | ||
|
||
// Store the updated array in local storage | ||
localStorage.setItem(key, JSON.stringify(items)); | ||
} | ||
|
||
/** | ||
* Get all valid (non-expired) items from an array in local storage. | ||
* @param {string} key - The key of the array to retrieve. | ||
* @returns {Array} An array of valid items. | ||
*/ | ||
static getItems(key) { | ||
const itemStr = localStorage.getItem(key); | ||
|
||
// If the item doesn't exist, return an empty array | ||
if (!itemStr) { | ||
return []; | ||
} | ||
|
||
const items = JSON.parse(itemStr); | ||
const now = new Date(); | ||
const validItems = []; | ||
|
||
// Filter out expired items | ||
for (let item of items) { | ||
if (now.getTime() <= item.expiry) { | ||
validItems.push(item.value); | ||
} | ||
} | ||
|
||
// Update local storage with only valid items | ||
localStorage.setItem(key, JSON.stringify(validItems.map(value => ({ | ||
value, | ||
expiry: items.find(item => item.value === value).expiry | ||
})))); | ||
|
||
return validItems; | ||
} | ||
|
||
/** | ||
* Remove a specific item from the array in local storage. | ||
* @param {string} key - The key of the array. | ||
* @param {*} value - The value to be removed. | ||
*/ | ||
static removeItem(key, value) { | ||
const itemStr = localStorage.getItem(key); | ||
|
||
// If the item doesn't exist, return | ||
if (!itemStr) { | ||
return; | ||
} | ||
|
||
let items = JSON.parse(itemStr); | ||
|
||
// Filter out the item to be removed | ||
items = items.filter(item => item.value !== value); | ||
|
||
// Update local storage with the remaining items | ||
localStorage.setItem(key, JSON.stringify(items)); | ||
} | ||
} | ||
|
||
// Usage example: | ||
|
||
// Add items with different TTLs | ||
// ExpiringLocalStorage.addItem('myArray', 'item1', 10000); // Expires in 10 seconds | ||
// ExpiringLocalStorage.addItem('myArray', 'item2', 20000); // Expires in 20 seconds | ||
|
||
// Get all valid items (non-expired) | ||
// console.log(ExpiringLocalStorage.getItems('myArray')); | ||
|
||
// Remove a specific item | ||
// ExpiringLocalStorage.removeItem('myArray', 'item1'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1193,6 +1193,16 @@ | |
"@keplr-wallet/crypto" "0.12.28" | ||
semver "^7.5.0" | ||
|
||
"@chain-registry/[email protected]": | ||
version "1.68.2" | ||
resolved "https://registry.yarnpkg.com/@chain-registry/keplr/-/keplr-1.68.2.tgz#d322db5317e3c5299aa3cf62d1971403ed08fd31" | ||
integrity sha512-H3rdf/cLx7bNyyKo+1nI9HpLTlLzyeqi0Rmt+ggwtFRC63ZmDaMg/3vPY4rHvu38OdcaOid4Nyfc+7h3EEPW8Q== | ||
dependencies: | ||
"@chain-registry/types" "^0.45.1" | ||
"@keplr-wallet/cosmos" "0.12.28" | ||
"@keplr-wallet/crypto" "0.12.28" | ||
semver "^7.5.0" | ||
|
||
"@chain-registry/keplr@^1.64.2": | ||
version "1.64.2" | ||
resolved "https://registry.yarnpkg.com/@chain-registry/keplr/-/keplr-1.64.2.tgz#254f392a8a2db285daa75dd849fb652e1973cf39" | ||
|
@@ -1213,6 +1223,11 @@ | |
resolved "https://registry.yarnpkg.com/@chain-registry/types/-/types-0.41.1.tgz#0da38b579265456ded54d556f8da6a555babd086" | ||
integrity sha512-YZcmYjc1N4eOSd5Vi8rT1CtIDNvcqVoSNPBImfEqpBG+NBokO02WVQtsflFi4/MYRkLQQIHN7yDok09hld+c+Q== | ||
|
||
"@chain-registry/types@^0.45.1": | ||
version "0.45.1" | ||
resolved "https://registry.yarnpkg.com/@chain-registry/types/-/types-0.45.1.tgz#bbe8cb65d80cf6be658f9eb0840eb72648d8cd08" | ||
integrity sha512-xDq3RZwLM6VZt7Bwrilm588xTce7mOZIpLIjpwaT/V6HD3TuzJC3FWMRAxUtMuhQldcjW8b8em5HdFY467FRhA== | ||
|
||
"@chain-registry/utils@^1.42.3": | ||
version "1.42.3" | ||
resolved "https://registry.yarnpkg.com/@chain-registry/utils/-/utils-1.42.3.tgz#90ad49d19bc095e991fa89bffaa70eaa8d9e8618" | ||
|