-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Submit Transaction: default to last selected method (#1103)
- Loading branch information
Showing
4 changed files
with
61 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { LOCAL_STORAGE_SETTINGS } from "@/constants/settings"; | ||
import { isEmptyObject } from "@/helpers/isEmptyObject"; | ||
import { LabSettings } from "@/types/types"; | ||
|
||
export const localStorageSubmitMethod = { | ||
get: (key: string) => { | ||
const labSettings = getSettings(); | ||
return labSettings[key]; | ||
}, | ||
set: ({ key, value }: LabSettings) => { | ||
const updatedSettings = { | ||
...getSettings(), | ||
[key]: value, | ||
}; | ||
|
||
return localStorage.setItem( | ||
LOCAL_STORAGE_SETTINGS, | ||
JSON.stringify(updatedSettings), | ||
); | ||
}, | ||
remove: (key: string) => { | ||
const updatedSettings = { ...getSettings() }; | ||
|
||
if (updatedSettings[key]) { | ||
delete updatedSettings[key]; | ||
|
||
if (isEmptyObject(updatedSettings)) { | ||
return localStorage.removeItem(LOCAL_STORAGE_SETTINGS); | ||
} | ||
} | ||
|
||
return localStorage.setItem( | ||
LOCAL_STORAGE_SETTINGS, | ||
JSON.stringify(updatedSettings), | ||
); | ||
}, | ||
}; | ||
|
||
const getSettings = () => { | ||
const labSettings = localStorage.getItem(LOCAL_STORAGE_SETTINGS); | ||
return labSettings ? (JSON.parse(labSettings) as LabSettings) : {}; | ||
}; |
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