-
Notifications
You must be signed in to change notification settings - Fork 11
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 #194 from jayden-sudo/develop
SoulWallet instances add parameter `_config` that can skip on-chain d…
- Loading branch information
Showing
3 changed files
with
82 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@soulwallet/sdk": patch | ||
--- | ||
|
||
SoulWallet instances add parameter `_config` that can skip on-chain detection |
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,45 @@ | ||
export class MemCache { | ||
private static instance?: MemCache = undefined; | ||
|
||
public static getInstance(): MemCache { | ||
if (!MemCache.instance) | ||
MemCache.instance = new MemCache(); | ||
return MemCache.instance!; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
private storage: Record<string, any> = {}; | ||
|
||
private constructor() { } | ||
|
||
/** | ||
* | ||
* | ||
* @template T | ||
* @param {string} key | ||
* @param {T} value | ||
*/ | ||
public set<T>(key: string, value: T) { | ||
if (value === undefined) { | ||
throw new Error("value is undefined"); | ||
} | ||
this.storage[key] = value; | ||
} | ||
|
||
/** | ||
* | ||
* | ||
* @template T | ||
* @param {string} key | ||
* @param {T} defaultValue | ||
* @return {*} {T} | ||
*/ | ||
public get<T>(key: string, defaultValue: T): T { | ||
if (key in this.storage) { | ||
const v = this.storage[key] as T; | ||
if (v !== undefined) { | ||
return v; | ||
} | ||
} | ||
return defaultValue; | ||
} | ||
} |