forked from comit-network/xmr-btc-swap
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsettingsSlice.ts
151 lines (143 loc) · 4.02 KB
/
settingsSlice.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { Theme } from "renderer/components/theme";
export interface SettingsState {
/// This is an ordered list of node urls for each network and blockchain
nodes: Record<Network, Record<Blockchain, string[]>>;
/// Which theme to use
theme: Theme;
/// Whether to fetch fiat prices from the internet
fetchFiatPrices: boolean;
fiatCurrency: FiatCurrency;
}
export enum FiatCurrency {
Usd = "USD",
Eur = "EUR",
Gbp = "GBP",
Chf = "CHF",
Jpy = "JPY",
// the following are copied from the coin gecko API and claude, not sure if they all work
Aed = "AED",
Ars = "ARS",
Aud = "AUD",
Bdt = "BDT",
Bhd = "BHD",
Bmd = "BMD",
Brl = "BRL",
Cad = "CAD",
Clp = "CLP",
Cny = "CNY",
Czk = "CZK",
Dkk = "DKK",
Gel = "GEL",
Hkd = "HKD",
Huf = "HUF",
Idr = "IDR",
Ils = "ILS",
Inr = "INR",
Krw = "KRW",
Kwd = "KWD",
Lkr = "LKR",
Mmk = "MMK",
Mxn = "MXN",
Myr = "MYR",
Ngn = "NGN",
Nok = "NOK",
Nzd = "NZD",
Php = "PHP",
Pkr = "PKR",
Pln = "PLN",
Rub = "RUB",
Sar = "SAR",
Sek = "SEK",
Sgd = "SGD",
Thb = "THB",
Try = "TRY",
Twd = "TWD",
Uah = "UAH",
Ves = "VES",
Vnd = "VND",
Zar = "ZAR",
}
export enum Network {
Testnet = "testnet",
Mainnet = "mainnet"
}
export enum Blockchain {
Bitcoin = "bitcoin",
Monero = "monero"
}
const initialState: SettingsState = {
nodes: {
[Network.Testnet]: {
[Blockchain.Bitcoin]: [
"ssl://blockstream.info:993",
"tcp://blockstream.info:143",
"ssl://testnet.aranguren.org:51002",
"tcp://testnet.aranguren.org:51001",
"ssl://bitcoin.stagemole.eu:5010",
"tcp://bitcoin.stagemole.eu:5000",
],
[Blockchain.Monero]: []
},
[Network.Mainnet]: {
[Blockchain.Bitcoin]: [
"ssl://electrum.blockstream.info:50002",
"tcp://electrum.blockstream.info:50001",
"ssl://bitcoin.stackwallet.com:50002",
"ssl://b.1209k.com:50002",
"tcp://electrum.coinucopia.io:50001",
],
[Blockchain.Monero]: []
}
},
theme: Theme.Darker,
fetchFiatPrices: true,
fiatCurrency: FiatCurrency.Usd,
};
const alertsSlice = createSlice({
name: "settings",
initialState,
reducers: {
moveUpNode(slice, action: PayloadAction<{ network: Network, type: Blockchain, node: string }>) {
const index = slice.nodes[action.payload.network][action.payload.type].indexOf(action.payload.node);
if (index > 0) {
const temp = slice.nodes[action.payload.network][action.payload.type][index];
slice.nodes[action.payload.network][action.payload.type][index] = slice.nodes[action.payload.network][action.payload.type][index - 1];
slice.nodes[action.payload.network][action.payload.type][index - 1] = temp;
}
},
setTheme(slice, action: PayloadAction<Theme>) {
slice.theme = action.payload;
},
setFetchFiatPrices(slice, action: PayloadAction<boolean>) {
slice.fetchFiatPrices = action.payload;
},
setFiatCurrency(slice, action: PayloadAction<FiatCurrency>) {
slice.fiatCurrency = action.payload;
},
addNode(slice, action: PayloadAction<{ network: Network, type: Blockchain, node: string }>) {
// Make sure the node is not already in the list
if (slice.nodes[action.payload.network][action.payload.type].includes(action.payload.node)) {
return;
}
// Add the node to the list
slice.nodes[action.payload.network][action.payload.type].push(action.payload.node);
},
removeNode(slice, action: PayloadAction<{ network: Network, type: Blockchain, node: string }>) {
slice.nodes[action.payload.network][action.payload.type] = slice.nodes[action.payload.network][action.payload.type].filter(node => node !== action.payload.node);
},
resetSettings(_) {
return initialState;
}
},
});
export const {
moveUpNode,
setTheme,
addNode,
removeNode,
resetSettings,
setFetchFiatPrices,
setFiatCurrency,
} = alertsSlice.actions;
export default alertsSlice.reducer;