Skip to content

Commit 55b9924

Browse files
committed
Multi fiat currency selection
1 parent 6965c25 commit 55b9924

File tree

10 files changed

+143
-12
lines changed

10 files changed

+143
-12
lines changed

src/components/input-group/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ export default ({
7979
<span className={'custom-input-label'}>{label}</span>
8080
{showFiatFromSatsValue ? (
8181
<span className={'custom-input-fiat-conversion'}>
82-
${fiat.fiatWhole}
82+
{fiat.fiatSymbol}
83+
{fiat.fiatWhole}
8384
<span className={'decimal'}>
8485
{fiat.fiatDecimal}
8586
{fiat.fiatDecimalValue}

src/components/value-group/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export default ({
3333
{showFiat ? (
3434
<span className={'value-group-convert'}>
3535
{' '}
36-
${displayValues.fiatWhole}
36+
{displayValues.fiatSymbol}
37+
{displayValues.fiatWhole}
3738
<span className={'decimal'}>
3839
{displayValues.fiatDecimal}
3940
{displayValues.fiatDecimalValue}

src/hooks/displayValues.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {
66
TBitcoinUnit
77
} from '../utils/exchange-rates';
88
import { useAppSelector } from '../store/hooks';
9-
import { selectExchangeRates, selectExchangeRateState } from '../store/public-store';
9+
import {
10+
selectCurrency,
11+
selectExchangeRates,
12+
selectExchangeRateState
13+
} from '../store/public-store';
1014

1115
export default function useDisplayValues(sats: number): IDisplayValues {
1216
const exchangeRates = useAppSelector(selectExchangeRates);
@@ -15,7 +19,7 @@ export default function useDisplayValues(sats: number): IDisplayValues {
1519

1620
// TODO allow these to be set
1721
const bitcoinUnit: TBitcoinUnit = 'satoshi';
18-
const selectedCurrency = 'USD';
22+
const selectedCurrency = useAppSelector(selectCurrency);
1923

2024
useEffect((): void => {
2125
// Exchange rates haven't loaded yet

src/pages/public/claim/index.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ function ClaimPage(): JSX.Element {
144144
<div className={'claim-channel-title-container'}>
145145
<span className={'claim-channel-title'}>Inbound capacity</span>
146146
<span className={'channel-claim-fiat-conversion'}>
147-
${inboundDisplay.fiatWhole}
147+
{inboundDisplay.fiatSymbol}
148+
{inboundDisplay.fiatWhole}
148149
<span className={'decimal'}>
149150
{inboundDisplay.fiatDecimal}
150151
{inboundDisplay.fiatDecimalValue}
@@ -160,7 +161,8 @@ function ClaimPage(): JSX.Element {
160161
<div className={'claim-channel-title-container'}>
161162
<span className={'claim-channel-title'}>My balance</span>
162163
<span className={'channel-claim-fiat-conversion'}>
163-
${myBalanceDisplay.fiatWhole}
164+
{myBalanceDisplay.fiatSymbol}
165+
{myBalanceDisplay.fiatWhole}
164166
<span className={'decimal'}>
165167
{myBalanceDisplay.fiatDecimal}
166168
{myBalanceDisplay.fiatDecimalValue}

src/pages/public/index.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import PaymentPage from './payment';
88
import ClaimPage from './claim';
99
import TermsPage from './terms';
1010
import MenuPage from './menu';
11+
import SettingsPage from './settings';
1112
import ErrorPage from './error';
1213
import FullWebpageContainer from '../../components/full-webpage-container';
1314
import { useAppSelector } from '../../store/hooks';
@@ -41,6 +42,9 @@ export const Widget = (): JSX.Element => {
4142
case 'terms': {
4243
return <TermsPage />;
4344
}
45+
case 'settings': {
46+
return <SettingsPage />;
47+
}
4448
case 'geoblocked': {
4549
return <ErrorPage type={'geoblocked'} />;
4650
}

src/pages/public/menu/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function MenuPage(): JSX.Element {
4444
const options: TMenuItem[] = [
4545
{ title: 'New channel', page: 'configure' },
4646
{ title: 'My orders', page: 'orders' },
47+
{ title: 'Settings', page: 'settings' },
4748
{ title: 'Support', href: supportHref() } // TODO
4849
];
4950

src/pages/public/settings/index.scss

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.settings-container {
2+
.settings-heading {
3+
color: #FF6600;
4+
font-style: normal;
5+
font-weight: 600;
6+
font-size: 15px;
7+
line-height: 22px;
8+
}
9+
10+
.settings-subheading {
11+
font-style: normal;
12+
font-weight: 400;
13+
font-size: 21px;
14+
line-height: 24px;
15+
color: #FFFFFF;
16+
}
17+
18+
.currency-box {
19+
cursor: pointer;
20+
background: rgba(255, 174, 0, 0.08);
21+
box-sizing: border-box;
22+
border-radius: 8px;
23+
padding: 10px 20px;
24+
display: flex;
25+
justify-content: space-between;
26+
align-items: center;
27+
margin-bottom: 10px;
28+
29+
.currency-name {
30+
font-style: normal;
31+
font-weight: 600;
32+
font-size: 15px;
33+
letter-spacing: -0.4px;
34+
color: #FFFFFF;
35+
}
36+
37+
.currency-symbol {
38+
font-style: normal;
39+
font-weight: 700;
40+
font-size: 34px;
41+
text-align: center;
42+
color: #FFFFFF;
43+
}
44+
}
45+
46+
.currency-box-active {
47+
border: 1px solid #FFAE00;
48+
}
49+
}

src/pages/public/settings/index.tsx

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react';
2+
import { useAppDispatch, useAppSelector } from '../../../store/hooks';
3+
import FormCard from '../../../components/form-card';
4+
import './index.scss';
5+
import { fiatDetails, supportedFiatTickers, TFiatCurrency } from '../../../utils/exchange-rates';
6+
import { refreshExchangeRates, selectCurrency, setCurrency } from '../../../store/public-store';
7+
8+
function SettingsPage(): JSX.Element {
9+
const dispatch = useAppDispatch();
10+
const selected = useAppSelector(selectCurrency);
11+
12+
const onSelect = (currency: TFiatCurrency): void => {
13+
dispatch(setCurrency(currency));
14+
dispatch(refreshExchangeRates());
15+
};
16+
17+
return (
18+
<FormCard title={'Settings'} backPage={'configure'}>
19+
<div className={'settings-container'}>
20+
<h5 className={'settings-heading'}>Currency</h5>
21+
22+
<p className={'settings-subheading'}>Select your preferred currency</p>
23+
24+
{supportedFiatTickers.map((c) => {
25+
const active = selected === c;
26+
const name = fiatDetails[c] ? `(${fiatDetails[c].name})` : '';
27+
const symbol = fiatDetails[c] ? fiatDetails[c].symbol : '';
28+
29+
return (
30+
<div
31+
key={c}
32+
className={`currency-box ${active ? 'currency-box-active' : ''}`}
33+
onClick={() => onSelect(c)}
34+
>
35+
<span className={'currency-name'}>
36+
{c} {name}
37+
</span>
38+
<span className={'currency-symbol'}>{symbol}</span>
39+
</div>
40+
);
41+
})}
42+
</div>
43+
</FormCard>
44+
);
45+
}
46+
47+
export default SettingsPage;

src/store/public-store.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import bt, {
66
IGetInfoResponse,
77
IGetOrderResponse
88
} from '@synonymdev/blocktank-client';
9+
import { TFiatCurrency } from '../utils/exchange-rates';
910

1011
export type RequestState = 'idle' | 'loading' | 'error';
1112

@@ -16,16 +17,23 @@ export type TPublicPage =
1617
| 'claim'
1718
| 'order'
1819
| 'orders'
20+
| 'settings'
1921
| 'terms'
2022
| 'geoblocked';
23+
2124
export type TNavigationState = {
2225
page: TPublicPage;
2326
orderId?: string;
2427
showMenu?: boolean;
2528
};
2629

30+
export type TSettingsState = {
31+
currency: TFiatCurrency;
32+
};
33+
2734
export type TState = {
2835
navigation: TNavigationState;
36+
settings: TSettingsState;
2937
info: {
3038
state: RequestState;
3139
value: IGetInfoResponse;
@@ -45,6 +53,9 @@ export const initialState: TState = {
4553
page: 'configure',
4654
showMenu: false
4755
},
56+
settings: {
57+
currency: 'USD'
58+
},
4859
info: {
4960
state: 'idle',
5061
value: {
@@ -97,9 +108,12 @@ export const publicStore = createSlice({
97108
setShowMenu: (state, action: PayloadAction<boolean>) => {
98109
state.navigation.showMenu = action.payload;
99110
},
111+
setCurrency: (state, action: PayloadAction<TFiatCurrency>) => {
112+
state.settings.currency = action.payload;
113+
},
100114
setOrderId: (state, action: PayloadAction<string>) => {
101115
state.navigation.orderId = action.payload;
102-
},
116+
}
103117
},
104118
extraReducers: (builder) => {
105119
builder
@@ -157,13 +171,14 @@ export const publicStore = createSlice({
157171
}
158172
});
159173

160-
export const { navigate, setShowMenu, setOrderId } = publicStore.actions;
174+
export const { navigate, setShowMenu, setCurrency, setOrderId } = publicStore.actions;
161175

162176
// The function below is called a selector and allows us to select a value from
163177
// the state. Selectors can also be defined inline where they're used instead of
164178
// in the slice file. For example: `useSelector((state: RootState) => state.counter.value)`
165179
export const selectCurrentPage = (state: RootState): TPublicPage => state.bt.navigation.page;
166180
export const selectShowMenu = (state: RootState): boolean => !!state.bt.navigation.showMenu;
181+
export const selectCurrency = (state: RootState): TFiatCurrency => state.bt.settings.currency;
167182
export const selectCurrentOrderId = (state: RootState): string => state.bt.navigation.orderId ?? '';
168183

169184
export const selectInfo = (state: RootState): IGetInfoResponse => state.bt.info.value;

src/utils/exchange-rates.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import bitcoinUnits from 'bitcoin-units';
22

3-
export const supportedExchangeTickers = ['USD', 'EUR', 'JPY', 'GBP'];
3+
export type TFiatCurrency = 'USD' | 'EUR' | 'JPY' | 'GBP';
4+
export const supportedFiatTickers: TFiatCurrency[] = ['USD', 'EUR', 'JPY', 'GBP'];
5+
export const fiatDetails: { [key: string]: { symbol: string; name: string } } = {
6+
USD: { name: 'United States Dollar', symbol: '$' },
7+
EUR: { name: 'Euro', symbol: '€' },
8+
JPY: { name: 'Japanese Yen', symbol: '¥' },
9+
GBP: { name: 'Great British Pound', symbol: '£' }
10+
};
411

512
export type TBitcoinUnit = 'satoshi' | 'BTC' | 'mBTC' | 'μBTC';
613

@@ -10,7 +17,7 @@ export type IDisplayValues = {
1017
fiatDecimal: string; // Decimal point "." or ","
1118
fiatDecimalValue: string; // Value after decimal point
1219
fiatSymbol: string; // $,€,£
13-
fiatTicker: string; // USD, EUR
20+
fiatTicker: TFiatCurrency; // USD, EUR
1421
bitcoinFormatted: string;
1522
bitcoinSymbol: string; // ₿, m₿, μ₿, ⚡,
1623
bitcoinTicker: string; // BTC, mBTC, μBTC, Sats
@@ -26,7 +33,7 @@ export const defaultDisplayValues: IDisplayValues = {
2633
fiatDecimal: '',
2734
fiatDecimalValue: '',
2835
fiatSymbol: '',
29-
fiatTicker: '',
36+
fiatTicker: 'USD',
3037
bitcoinFormatted: '-',
3138
bitcoinSymbol: '',
3239
bitcoinTicker: '',
@@ -49,7 +56,7 @@ export const getDisplayValues = ({
4956
}: {
5057
satoshis: number;
5158
exchangeRate?: number;
52-
currency: string;
59+
currency: TFiatCurrency;
5360
bitcoinUnit: TBitcoinUnit;
5461
locale?: string;
5562
}): IDisplayValues => {

0 commit comments

Comments
 (0)