Skip to content

Commit

Permalink
refactor: use static fields instead of exports
Browse files Browse the repository at this point in the history
Signed-off-by: rare-magma <[email protected]>
  • Loading branch information
rare-magma committed Oct 5, 2024
1 parent c27ce98 commit e33b2cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/guitos/domain/userOptions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { IntlConfig } from "react-currency-input-field/dist/components/CurrencyInputProps";
import { currenciesList } from "../../lists/currenciesList";

export const CURRENCY_CODE = "currencyCode";
export const LOCALE = "locale";

export class UserOptions {
currencyCode: string;
locale: string;
static CURRENCY_CODE = "currencyCode";
static LOCALE = "locale";

constructor(currencyCode: string, locale: string) {
this.currencyCode = currencyCode;
Expand Down
16 changes: 10 additions & 6 deletions src/guitos/infrastructure/localForageOptionsRepository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import localforage from "localforage";
import { currenciesMap } from "../../lists/currenciesMap";
import { CURRENCY_CODE, LOCALE } from "../domain/userOptions";
import type { UserOptions } from "../domain/userOptions";
import { UserOptions } from "../domain/userOptions";
import type { UserOptionsRepository } from "../domain/userOptionsRepository";

export class localForageOptionsRepository implements UserOptionsRepository {
Expand All @@ -16,7 +15,9 @@ export class localForageOptionsRepository implements UserOptionsRepository {

async getCurrencyCode(): Promise<string> {
try {
const code = await this.optionsDB.getItem<string>(CURRENCY_CODE);
const code = await this.optionsDB.getItem<string>(
UserOptions.CURRENCY_CODE,
);
if (!code) {
return this.getDefaultCurrencyCode();
}
Expand All @@ -28,7 +29,10 @@ export class localForageOptionsRepository implements UserOptionsRepository {

async saveCurrencyCode(options: UserOptions): Promise<boolean> {
try {
await this.optionsDB.setItem<string>(CURRENCY_CODE, options.currencyCode);
await this.optionsDB.setItem<string>(
UserOptions.CURRENCY_CODE,
options.currencyCode,
);
return true;
} catch {
return false;
Expand All @@ -37,7 +41,7 @@ export class localForageOptionsRepository implements UserOptionsRepository {

async getLocale(): Promise<string> {
try {
const locale = await this.optionsDB.getItem<string>(LOCALE);
const locale = await this.optionsDB.getItem<string>(UserOptions.LOCALE);
if (!locale) throw new Error();
return locale;
} catch (e) {
Expand All @@ -47,7 +51,7 @@ export class localForageOptionsRepository implements UserOptionsRepository {

async saveLocale(options: UserOptions): Promise<boolean> {
try {
await this.optionsDB.setItem<string>(LOCALE, options.locale);
await this.optionsDB.setItem<string>(UserOptions.LOCALE, options.locale);
return true;
} catch {
return false;
Expand Down

0 comments on commit e33b2cb

Please sign in to comment.