Skip to content

Commit 85e72c7

Browse files
committed
frontend: rename fn names w/ 'fiat' to 'currency' in RatesProvider
1 parent 59127c8 commit 85e72c7

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

frontends/web/src/components/rates/rates.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ export const DefaultCurrencyRotator = ({
133133
className = '',
134134
tableRow = true
135135
}: TDefaultCurrencyRotator) => {
136-
const { rotateFiat, defaultCurrency } = useContext(RatesContext);
136+
const { rotateDefaultCurrency, defaultCurrency } = useContext(RatesContext);
137137
const displayedCurrency = activeUnit ? activeUnit : defaultCurrency;
138138
const textStyle = `${className} ${style.rotatable}`;
139139
if (!tableRow) {
140-
return <span className={textStyle} onClick={rotateFiat}>{displayedCurrency}</span>;
140+
return <span className={textStyle} onClick={rotateDefaultCurrency}>{displayedCurrency}</span>;
141141
}
142-
return <td className={textStyle} onClick={rotateFiat}>{displayedCurrency}</td>;
142+
return <td className={textStyle} onClick={rotateDefaultCurrency}>{displayedCurrency}</td>;
143143
};
144144

145145
export const formattedCurrencies = currenciesWithDisplayName.map((fiat) => ({ label: `${fiat.displayName} (${fiat.currency})`, value: fiat.currency }));

frontends/web/src/contexts/RatesContext.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ type RatesContextProps = {
2222
defaultCurrency: Fiat;
2323
activeCurrencies: Fiat[];
2424
btcUnit?: BtcUnit;
25-
rotateFiat: () => Promise<void>;
26-
selectFiat: (fiat: Fiat) => Promise<void>;
27-
updateDefaultFiat: (fiat: Fiat) => void;
25+
rotateDefaultCurrency: () => Promise<void>;
26+
addToActiveCurrencies: (fiat: Fiat) => Promise<void>;
27+
updateDefaultCurrency: (fiat: Fiat) => void;
2828
updateRatesConfig: () => Promise<void>;
29-
unselectFiat: (fiat: Fiat) => Promise<void>;
29+
removeFromActiveCurrencies: (fiat: Fiat) => Promise<void>;
3030
}
3131

3232
const RatesContext = createContext<RatesContextProps>({} as RatesContextProps);

frontends/web/src/contexts/RatesProvider.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,33 @@ export const RatesProvider = ({ children }: TProps) => {
4848
}
4949
};
5050

51-
const rotateFiat = async () => {
51+
const rotateDefaultCurrency = async () => {
5252
const index = activeCurrencies.indexOf(defaultCurrency);
5353
const fiat = activeCurrencies[(index + 1) % activeCurrencies.length];
54-
await updateDefaultFiat(fiat);
54+
await updateDefaultCurrency(fiat);
5555
};
5656

57-
const updateDefaultFiat = async (fiat: Fiat) => {
57+
// sets default currency both in config (mainFiat)
58+
// and in RatesContext context's (local) state
59+
const updateDefaultCurrency = async (fiat: Fiat) => {
5860
if (!activeCurrencies.includes(fiat)) {
59-
selectFiat(fiat);
61+
addToActiveCurrencies(fiat);
6062
}
6163
await setConfig({ backend: { mainFiat: fiat } });
6264
setDefaultCurrency(fiat);
6365
};
6466

65-
//this is a method to select a fiat to be
66-
//added into the selected fiat list
67-
const selectFiat = async (fiat: Fiat) => {
67+
// this is a method to select / add a currency
68+
// into the active currencies list
69+
const addToActiveCurrencies = async (fiat: Fiat) => {
6870
const selected = [...activeCurrencies, fiat];
6971
await setConfig({ backend: { fiatList: selected } });
7072
handleChangeSelectedFiat(selected);
7173
};
7274

73-
//this is a method to unselect a fiat to be
74-
//removed from the selected fiat list
75-
const unselectFiat = async (fiat: Fiat) => {
75+
// this is a method to unselect / remove a currency
76+
// from the active currencies list
77+
const removeFromActiveCurrencies = async (fiat: Fiat) => {
7678
const selected = activeCurrencies.filter(item => !equal(item, fiat));
7779
await setConfig({ backend: { fiatList: selected } });
7880
handleChangeSelectedFiat(selected);
@@ -91,11 +93,11 @@ export const RatesProvider = ({ children }: TProps) => {
9193
defaultCurrency,
9294
activeCurrencies,
9395
btcUnit,
94-
rotateFiat,
95-
selectFiat,
96-
updateDefaultFiat,
96+
rotateDefaultCurrency,
97+
addToActiveCurrencies,
98+
updateDefaultCurrency,
9799
updateRatesConfig,
98-
unselectFiat
100+
removeFromActiveCurrencies
99101
}}
100102
>
101103
{children}

frontends/web/src/routes/settings/components/appearance/defaultCurrencyDropdownSetting.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { RatesContext } from '../../../../contexts/RatesContext';
2424

2525
export const DefaultCurrencyDropdownSetting = () => {
2626
const { t } = useTranslation();
27-
const { selectFiat, updateDefaultFiat, defaultCurrency, activeCurrencies } = useContext(RatesContext);
27+
const { addToActiveCurrencies, updateDefaultCurrency, defaultCurrency, activeCurrencies } = useContext(RatesContext);
2828
const valueLabel = currenciesWithDisplayName.find(fiat => fiat.currency === defaultCurrency)?.displayName;
2929
const defaultValueLabel = valueLabel ? `${valueLabel} (${defaultCurrency})` : defaultCurrency;
3030
return (
@@ -36,9 +36,9 @@ export const DefaultCurrencyDropdownSetting = () => {
3636
<SingleDropdown
3737
options={formattedCurrencies}
3838
handleChange={async (fiat: Fiat) => {
39-
updateDefaultFiat(fiat);
39+
updateDefaultCurrency(fiat);
4040
if (!activeCurrencies.includes(fiat)) {
41-
await selectFiat(fiat);
41+
await addToActiveCurrencies(fiat);
4242
}
4343
}}
4444
defaultValue={{

frontends/web/src/routes/settings/components/dropdowns/activecurrenciesdropdown.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const ActiveCurrenciesDropdown = ({
2828
const [search, setSearch] = useState('');
2929
const { t } = useTranslation();
3030

31-
const { unselectFiat, selectFiat } = useContext(RatesContext);
31+
const { removeFromActiveCurrencies, addToActiveCurrencies } = useContext(RatesContext);
3232

3333
useEffect(() => {
3434
if (activeCurrencies.length > 0) {
@@ -77,12 +77,12 @@ export const ActiveCurrenciesDropdown = ({
7777
switch (meta.action) {
7878
case 'select-option':
7979
if (meta.option) {
80-
await selectFiat(meta.option.value);
80+
await addToActiveCurrencies(meta.option.value);
8181
}
8282
break;
8383
case 'deselect-option':
8484
if (meta.option && meta.option.value !== defaultCurrency) {
85-
await unselectFiat(meta.option.value);
85+
await removeFromActiveCurrencies(meta.option.value);
8686
}
8787
}
8888
}}

0 commit comments

Comments
 (0)