-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: creating a cache for verified assets (#586)
- Loading branch information
1 parent
a5db047
commit c30391f
Showing
2 changed files
with
37 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default class VerifiedAssets { | ||
static instance: VerifiedAssets; | ||
private lastDate?: Date; | ||
private assets: any; | ||
|
||
private constructor() {} | ||
|
||
async fetch() { | ||
const now = new Date(); | ||
if ( | ||
!this.lastDate || | ||
!this.assets || | ||
now.getTime() - this.lastDate.getTime() > 60000 | ||
) { | ||
this.lastDate = new Date(); | ||
const response = await fetch( | ||
'https://verified-assets.fuel.network/assets.json', | ||
); | ||
this.assets = await response.json(); | ||
return this.assets; | ||
} | ||
return this.assets; | ||
} | ||
|
||
static getInstance() { | ||
if (!VerifiedAssets.instance) { | ||
VerifiedAssets.instance = new VerifiedAssets(); | ||
} | ||
return VerifiedAssets.instance; | ||
} | ||
} |