-
Notifications
You must be signed in to change notification settings - Fork 44
Discover V2 #2671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Discover V2 #2671
Changes from all commits
d6a2ce6
3b805d1
5746f87
a8c4866
95ea090
9890836
c180149
1099777
5a35340
50b3c08
8a17902
18b7a0f
e5b314d
0ecf85b
ab5f8c0
aea1ad2
6ee8491
cb2339d
d9e7c37
2509c15
7e02554
3bcaf62
b30a972
e999c53
f59150c
8321cc4
3cc3cfc
6dc2d5d
ccd20d8
6f2f8cd
1df31a3
a1f53b3
670d0c2
865a685
44981ce
e7b6dae
06df44a
f8b7df1
544dc77
c388362
de7a612
7891c21
010c6fb
1fc3b41
5717f5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import browser from "webextension-polyfill"; | ||
|
|
||
| const STORAGE_KEY = "recentProtocols"; | ||
| const MAX_RECENT = 5; | ||
|
|
||
| export interface RecentProtocolEntry { | ||
| websiteUrl: string; | ||
| lastAccessed: number; | ||
| } | ||
|
|
||
| export const getRecentProtocols = async (): Promise<RecentProtocolEntry[]> => { | ||
| const result = await browser.storage.local.get(STORAGE_KEY); | ||
| return (result[STORAGE_KEY] as RecentProtocolEntry[]) || []; | ||
| }; | ||
|
|
||
| export const addRecentProtocol = async (websiteUrl: string): Promise<void> => { | ||
| const existing = await getRecentProtocols(); | ||
| const filtered = existing.filter((entry) => entry.websiteUrl !== websiteUrl); | ||
| const updated = [{ websiteUrl, lastAccessed: Date.now() }, ...filtered].slice( | ||
| 0, | ||
| MAX_RECENT, | ||
| ); | ||
| await browser.storage.local.set({ [STORAGE_KEY]: updated }); | ||
| }; | ||
|
|
||
| export const clearRecentProtocols = async (): Promise<void> => { | ||
| await browser.storage.local.remove(STORAGE_KEY); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -97,6 +97,7 @@ | |||
| "Clear": "Clear", | ||||
| "Clear Flags": "Clear Flags", | ||||
| "Clear Override": "Clear Override", | ||||
| "Clear recents": "Clear recents", | ||||
| "Close": "Close", | ||||
| "Coinbase Logo": "Coinbase Logo", | ||||
| "Collectible": "Collectible", | ||||
|
|
@@ -146,6 +147,7 @@ | |||
| "Create new wallet": "Create new wallet", | ||||
| "Current Network": "Current Network", | ||||
| "Custom": "Custom", | ||||
| "dApps": "dApps", | ||||
| "Dapps": "Dapps", | ||||
|
||||
| "Dapps": "Dapps", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you start the extension in dev mode and load the extension in your browser at
http://localhost:9000/#/, this code won't be able to run. That's because browser.storage is only available in:or
Because of this, we keep all interactions with browser.storage in the background script and then transmit them to the UI. For ex: https://github.com/stellar/freighter/blob/master/extension/src/background/messageListener/popupMessageListener.ts#L353
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also a dual purpose here. By keeping all storage interactions in the
background, it makes it easier to track where storage changes were madeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's certainly up for debate if we want to keep using this pattern, but IMO, it's useful to keep this hot reloading dev experience and it's also good practice to keep storage concerns away from the UI