@lightsparkdev/lightspark-sdk 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +1 -1
- package/dist/{Withdrawal-17e1c8af.d.ts → Withdrawal-ebb4865c.d.ts} +393 -377
- package/dist/{chunk-N27QHRE4.js → chunk-XFOVS6EY.js} +56 -40
- package/dist/index.cjs +25 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/objects/index.cjs +24 -8
- package/dist/objects/index.d.ts +1 -1
- package/dist/objects/index.js +1 -1
- package/package.json +7 -2
- package/src/client.ts +0 -1
- package/src/objects/Account.ts +2 -2
- package/src/objects/Entity.ts +10 -2
- package/src/objects/Invoice.ts +1 -1
- package/src/objects/InvoiceData.ts +10 -1
- package/src/objects/LightningTransaction.ts +1 -1
- package/src/objects/LightsparkNodeStatus.ts +2 -0
- package/src/objects/OutgoingPayment.ts +1 -1
- package/src/objects/PaymentRequest.ts +1 -1
- package/src/objects/PaymentRequestData.ts +1 -1
- package/src/objects/Transaction.ts +1 -1
- package/src/objects/WebhookEventType.ts +10 -0
- package/src/objects/WithdrawalRequest.ts +12 -0
- package/.fossa.yml +0 -6
- package/.prettierrc +0 -1
- package/.turbo/turbo-build.log +0 -19
- package/.turbo/turbo-lint.log +0 -3
- package/dist/chunk-AGEUDR2V.js +0 -4498
- package/dist/client-3bba3f64.d.ts +0 -1302
- package/examples/node-scripts/authHelpers.ts +0 -20
- package/examples/node-scripts/createInvoice.ts +0 -64
- package/examples/node-scripts/example.ts +0 -288
- package/examples/node-scripts/getAccountDashboard.ts +0 -24
- package/examples/node-scripts/getNodeChannels.ts +0 -34
- package/examples/node-scripts/internalAuthHelpers.ts +0 -26
- package/examples/node-scripts/internal_example.ts +0 -296
- package/examples/node-scripts/package-lock.json +0 -887
- package/examples/node-scripts/package.json +0 -22
- package/examples/node-scripts/prettyPrintJsonForDocs.ts +0 -62
- package/examples/node-scripts/tsconfig.json +0 -27
- package/examples/oauth-example/README.md +0 -19
- package/examples/oauth-example/package-lock.json +0 -16071
- package/examples/oauth-example/package.json +0 -50
- package/examples/oauth-example/public/favicon.ico +0 -0
- package/examples/oauth-example/public/index.html +0 -43
- package/examples/oauth-example/public/logo192.png +0 -0
- package/examples/oauth-example/public/logo512.png +0 -0
- package/examples/oauth-example/public/manifest.json +0 -25
- package/examples/oauth-example/public/robots.txt +0 -3
- package/examples/oauth-example/src/App.css +0 -7
- package/examples/oauth-example/src/App.test.tsx +0 -12
- package/examples/oauth-example/src/App.tsx +0 -16
- package/examples/oauth-example/src/auth/AuthContext.ts +0 -8
- package/examples/oauth-example/src/auth/AuthProvider.tsx +0 -44
- package/examples/oauth-example/src/auth/RequireAuth.tsx +0 -19
- package/examples/oauth-example/src/auth/oauthProvider.ts +0 -35
- package/examples/oauth-example/src/components/Button.tsx +0 -39
- package/examples/oauth-example/src/components/CurrencyAmount.tsx +0 -117
- package/examples/oauth-example/src/components/Dashboard.tsx +0 -158
- package/examples/oauth-example/src/components/Table.tsx +0 -22
- package/examples/oauth-example/src/hooks/useAccountInfo.tsx +0 -31
- package/examples/oauth-example/src/icons/BitcoinB.tsx +0 -20
- package/examples/oauth-example/src/icons/Icon.tsx +0 -121
- package/examples/oauth-example/src/icons/Satoshi.tsx +0 -28
- package/examples/oauth-example/src/index.css +0 -13
- package/examples/oauth-example/src/index.tsx +0 -23
- package/examples/oauth-example/src/lightsparkclient/LightsparkClientContext.ts +0 -10
- package/examples/oauth-example/src/lightsparkclient/LightsparkClientProvider.tsx +0 -53
- package/examples/oauth-example/src/logo.svg +0 -1
- package/examples/oauth-example/src/pages/DashboardPage.tsx +0 -71
- package/examples/oauth-example/src/pages/LoginPage.tsx +0 -63
- package/examples/oauth-example/src/react-app-env.d.ts +0 -1
- package/examples/oauth-example/src/reportWebVitals.ts +0 -15
- package/examples/oauth-example/src/routes/index.tsx +0 -15
- package/examples/oauth-example/src/setupTests.ts +0 -5
- package/examples/oauth-example/src/utils/currency.ts +0 -483
- package/examples/oauth-example/tsconfig.json +0 -20
- package/examples/streaming-wallet-extension/.fossa.yml +0 -6
- package/examples/streaming-wallet-extension/README.md +0 -17
- package/examples/streaming-wallet-extension/craco.config.js +0 -58
- package/examples/streaming-wallet-extension/package-lock.json +0 -18260
- package/examples/streaming-wallet-extension/package.json +0 -77
- package/examples/streaming-wallet-extension/public/index.html +0 -24
- package/examples/streaming-wallet-extension/public/lightspark_full.png +0 -0
- package/examples/streaming-wallet-extension/public/lightspark_icon_circle.png +0 -0
- package/examples/streaming-wallet-extension/public/manifest.json +0 -43
- package/examples/streaming-wallet-extension/public/robots.txt +0 -3
- package/examples/streaming-wallet-extension/src/App.css +0 -53
- package/examples/streaming-wallet-extension/src/App.tsx +0 -425
- package/examples/streaming-wallet-extension/src/auth/AccountStorage.ts +0 -28
- package/examples/streaming-wallet-extension/src/auth/DemoAccountProvider.ts +0 -99
- package/examples/streaming-wallet-extension/src/auth/StreamingDemoCredentials.ts +0 -10
- package/examples/streaming-wallet-extension/src/background/PaymentStrategy.ts +0 -36
- package/examples/streaming-wallet-extension/src/background/PlaybackRange.ts +0 -31
- package/examples/streaming-wallet-extension/src/background/StreamingInvoiceHolder.ts +0 -33
- package/examples/streaming-wallet-extension/src/background/TransactionObserver.ts +0 -66
- package/examples/streaming-wallet-extension/src/background/VideoPlaybackRanges.ts +0 -38
- package/examples/streaming-wallet-extension/src/background/VideoProgressCache.ts +0 -87
- package/examples/streaming-wallet-extension/src/background/background.ts +0 -145
- package/examples/streaming-wallet-extension/src/background/messageHandling.ts +0 -185
- package/examples/streaming-wallet-extension/src/common/datetimes.ts +0 -28
- package/examples/streaming-wallet-extension/src/common/settings.ts +0 -12
- package/examples/streaming-wallet-extension/src/common/storage.ts +0 -8
- package/examples/streaming-wallet-extension/src/common/streamingTabs.ts +0 -27
- package/examples/streaming-wallet-extension/src/common/types.tsx +0 -23
- package/examples/streaming-wallet-extension/src/components/CirclePlusIcon.tsx +0 -19
- package/examples/streaming-wallet-extension/src/components/CurrencyAmount.tsx +0 -110
- package/examples/streaming-wallet-extension/src/components/CurrencyAmountRaw.tsx +0 -195
- package/examples/streaming-wallet-extension/src/components/LeftArrow.tsx +0 -21
- package/examples/streaming-wallet-extension/src/components/Loading.tsx +0 -151
- package/examples/streaming-wallet-extension/src/components/StreamingTransactionChip.tsx +0 -95
- package/examples/streaming-wallet-extension/src/components/TransactionRow.tsx +0 -93
- package/examples/streaming-wallet-extension/src/contentscript/content.ts +0 -123
- package/examples/streaming-wallet-extension/src/contentscript/lightsparkDemoDom.tsx +0 -113
- package/examples/streaming-wallet-extension/src/contentscript/videoElementParsers.ts +0 -92
- package/examples/streaming-wallet-extension/src/index.css +0 -16
- package/examples/streaming-wallet-extension/src/index.tsx +0 -11
- package/examples/streaming-wallet-extension/src/lightsparkClientProvider.tsx +0 -26
- package/examples/streaming-wallet-extension/src/react-app-env.d.ts +0 -1
- package/examples/streaming-wallet-extension/src/types/Messages.ts +0 -17
- package/examples/streaming-wallet-extension/tsconfig.json +0 -20
- package/tsconfig.json +0 -5
|
@@ -1,483 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CurrencyAmount,
|
|
3
|
-
CurrencyUnit,
|
|
4
|
-
} from "@lightsparkdev/lightspark-sdk";
|
|
5
|
-
|
|
6
|
-
const currentLocale = Intl.NumberFormat().resolvedOptions().locale;
|
|
7
|
-
const defaultCurrencyCode = "USD";
|
|
8
|
-
|
|
9
|
-
type CurrencyLocales = keyof typeof localeToCurrencyCodes;
|
|
10
|
-
export type CurrencyMap = {
|
|
11
|
-
sats: number;
|
|
12
|
-
msats: number;
|
|
13
|
-
btc: number;
|
|
14
|
-
[CurrencyUnit.BITCOIN]: number;
|
|
15
|
-
[CurrencyUnit.SATOSHI]: number;
|
|
16
|
-
[CurrencyUnit.MILLISATOSHI]: number;
|
|
17
|
-
[CurrencyUnit.MICROBITCOIN]: number;
|
|
18
|
-
[CurrencyUnit.MILLIBITCOIN]: number;
|
|
19
|
-
[CurrencyUnit.NANOBITCOIN]: number;
|
|
20
|
-
[CurrencyUnit.USD]: number;
|
|
21
|
-
[CurrencyUnit.FUTURE_VALUE]: number;
|
|
22
|
-
formatted: {
|
|
23
|
-
sats: string;
|
|
24
|
-
msats: string;
|
|
25
|
-
btc: string;
|
|
26
|
-
[CurrencyUnit.BITCOIN]: string;
|
|
27
|
-
[CurrencyUnit.SATOSHI]: string;
|
|
28
|
-
[CurrencyUnit.MILLISATOSHI]: string;
|
|
29
|
-
[CurrencyUnit.MILLIBITCOIN]: string;
|
|
30
|
-
[CurrencyUnit.MICROBITCOIN]: string;
|
|
31
|
-
[CurrencyUnit.NANOBITCOIN]: string;
|
|
32
|
-
[CurrencyUnit.USD]: string;
|
|
33
|
-
[CurrencyUnit.FUTURE_VALUE]: string;
|
|
34
|
-
};
|
|
35
|
-
isZero: boolean;
|
|
36
|
-
isLessThan: (other: CurrencyMap) => boolean;
|
|
37
|
-
isGreaterThan: (other: CurrencyMap) => boolean;
|
|
38
|
-
isEqualTo: (other: CurrencyMap) => boolean;
|
|
39
|
-
type: "CurrencyMap";
|
|
40
|
-
};
|
|
41
|
-
export type CurrencyAmountArg =
|
|
42
|
-
| {
|
|
43
|
-
/* technically the graphql schema has value as any as value but it returns a number in at least up to 18 or more
|
|
44
|
-
digits, which is over 100 billion dollars in millisats, so we can safely assume it's a number */
|
|
45
|
-
value?: number | null;
|
|
46
|
-
/* assume satoshi if not provided */
|
|
47
|
-
unit?: CurrencyUnit;
|
|
48
|
-
__typename?: "CurrencyAmount";
|
|
49
|
-
}
|
|
50
|
-
| undefined
|
|
51
|
-
| null;
|
|
52
|
-
|
|
53
|
-
/* From https://github.com/tadeegan/locale-currency. For now only USD conversion from
|
|
54
|
-
BTC is supported by sparkcore, strip additional currency codes from the bundle: */
|
|
55
|
-
const localeToCurrencyCodes = {
|
|
56
|
-
// AD: "EUR",
|
|
57
|
-
// AE: "AED",
|
|
58
|
-
// AF: "AFN",
|
|
59
|
-
// AG: "XCD",
|
|
60
|
-
// AI: "XCD",
|
|
61
|
-
// AL: "ALL",
|
|
62
|
-
// AM: "AMD",
|
|
63
|
-
// AO: "AOA",
|
|
64
|
-
// AR: "ARS",
|
|
65
|
-
AS: "USD",
|
|
66
|
-
// AT: "EUR",
|
|
67
|
-
// AU: "AUD",
|
|
68
|
-
// AW: "AWG",
|
|
69
|
-
// AX: "EUR",
|
|
70
|
-
// AZ: "AZN",
|
|
71
|
-
// BA: "BAM",
|
|
72
|
-
// BB: "BBD",
|
|
73
|
-
// BD: "BDT",
|
|
74
|
-
// BE: "EUR",
|
|
75
|
-
// BF: "XOF",
|
|
76
|
-
// BG: "BGN",
|
|
77
|
-
// BH: "BHD",
|
|
78
|
-
// BI: "BIF",
|
|
79
|
-
// BJ: "XOF",
|
|
80
|
-
// BL: "EUR",
|
|
81
|
-
// BM: "BMD",
|
|
82
|
-
// BN: "BND",
|
|
83
|
-
// BO: "BOB",
|
|
84
|
-
BQ: "USD",
|
|
85
|
-
// BR: "BRL",
|
|
86
|
-
// BS: "BSD",
|
|
87
|
-
// BT: "BTN",
|
|
88
|
-
// BV: "NOK",
|
|
89
|
-
// BW: "BWP",
|
|
90
|
-
// BY: "BYN",
|
|
91
|
-
// BZ: "BZD",
|
|
92
|
-
// CA: "CAD",
|
|
93
|
-
// CC: "AUD",
|
|
94
|
-
// CD: "CDF",
|
|
95
|
-
// CF: "XAF",
|
|
96
|
-
// CG: "XAF",
|
|
97
|
-
// CH: "CHF",
|
|
98
|
-
// CI: "XOF",
|
|
99
|
-
// CK: "NZD",
|
|
100
|
-
// CL: "CLP",
|
|
101
|
-
// CM: "XAF",
|
|
102
|
-
// CN: "CNY",
|
|
103
|
-
// CO: "COP",
|
|
104
|
-
// CR: "CRC",
|
|
105
|
-
// CU: "CUP",
|
|
106
|
-
// CV: "CVE",
|
|
107
|
-
// CW: "ANG",
|
|
108
|
-
// CX: "AUD",
|
|
109
|
-
// CY: "EUR",
|
|
110
|
-
// CZ: "CZK",
|
|
111
|
-
// DE: "EUR",
|
|
112
|
-
// DJ: "DJF",
|
|
113
|
-
// DK: "DKK",
|
|
114
|
-
// DM: "XCD",
|
|
115
|
-
// DO: "DOP",
|
|
116
|
-
// DZ: "DZD",
|
|
117
|
-
EC: "USD",
|
|
118
|
-
// EE: "EUR",
|
|
119
|
-
// EG: "EGP",
|
|
120
|
-
// EH: "MAD",
|
|
121
|
-
// ER: "ERN",
|
|
122
|
-
// ES: "EUR",
|
|
123
|
-
// ET: "ETB",
|
|
124
|
-
// FI: "EUR",
|
|
125
|
-
// FJ: "FJD",
|
|
126
|
-
// FK: "FKP",
|
|
127
|
-
FM: "USD",
|
|
128
|
-
// FO: "DKK",
|
|
129
|
-
// FR: "EUR",
|
|
130
|
-
// GA: "XAF",
|
|
131
|
-
// GB: "GBP",
|
|
132
|
-
// GD: "XCD",
|
|
133
|
-
// GE: "GEL",
|
|
134
|
-
// GF: "EUR",
|
|
135
|
-
// GG: "GBP",
|
|
136
|
-
// GH: "GHS",
|
|
137
|
-
// GI: "GIP",
|
|
138
|
-
// GL: "DKK",
|
|
139
|
-
// GM: "GMD",
|
|
140
|
-
// GN: "GNF",
|
|
141
|
-
// GP: "EUR",
|
|
142
|
-
// GQ: "XAF",
|
|
143
|
-
// GR: "EUR",
|
|
144
|
-
// GS: "GBP",
|
|
145
|
-
// GT: "GTQ",
|
|
146
|
-
GU: "USD",
|
|
147
|
-
// GW: "XOF",
|
|
148
|
-
// GY: "GYD",
|
|
149
|
-
// HK: "HKD",
|
|
150
|
-
// HM: "AUD",
|
|
151
|
-
// HN: "HNL",
|
|
152
|
-
// HR: "HRK",
|
|
153
|
-
// HT: "HTG",
|
|
154
|
-
// HU: "HUF",
|
|
155
|
-
// ID: "IDR",
|
|
156
|
-
// IE: "EUR",
|
|
157
|
-
// IL: "ILS",
|
|
158
|
-
// IM: "GBP",
|
|
159
|
-
// IN: "INR",
|
|
160
|
-
IO: "USD",
|
|
161
|
-
// IQ: "IQD",
|
|
162
|
-
// IR: "IRR",
|
|
163
|
-
// IS: "ISK",
|
|
164
|
-
// IT: "EUR",
|
|
165
|
-
// JE: "GBP",
|
|
166
|
-
// JM: "JMD",
|
|
167
|
-
// JO: "JOD",
|
|
168
|
-
// JP: "JPY",
|
|
169
|
-
// KE: "KES",
|
|
170
|
-
// KG: "KGS",
|
|
171
|
-
// KH: "KHR",
|
|
172
|
-
// KI: "AUD",
|
|
173
|
-
// KM: "KMF",
|
|
174
|
-
// KN: "XCD",
|
|
175
|
-
// KP: "KPW",
|
|
176
|
-
// KR: "KRW",
|
|
177
|
-
// KW: "KWD",
|
|
178
|
-
// KY: "KYD",
|
|
179
|
-
// KZ: "KZT",
|
|
180
|
-
// LA: "LAK",
|
|
181
|
-
// LB: "LBP",
|
|
182
|
-
// LC: "XCD",
|
|
183
|
-
// LI: "CHF",
|
|
184
|
-
// LK: "LKR",
|
|
185
|
-
// LR: "LRD",
|
|
186
|
-
// LS: "LSL",
|
|
187
|
-
// LT: "EUR",
|
|
188
|
-
// LU: "EUR",
|
|
189
|
-
// LV: "EUR",
|
|
190
|
-
// LY: "LYD",
|
|
191
|
-
// MA: "MAD",
|
|
192
|
-
// MC: "EUR",
|
|
193
|
-
// MD: "MDL",
|
|
194
|
-
// ME: "EUR",
|
|
195
|
-
// MF: "EUR",
|
|
196
|
-
// MG: "MGA",
|
|
197
|
-
MH: "USD",
|
|
198
|
-
// MK: "MKD",
|
|
199
|
-
// ML: "XOF",
|
|
200
|
-
// MM: "MMK",
|
|
201
|
-
// MN: "MNT",
|
|
202
|
-
// MO: "MOP",
|
|
203
|
-
MP: "USD",
|
|
204
|
-
// MQ: "EUR",
|
|
205
|
-
// MR: "MRO",
|
|
206
|
-
// MS: "XCD",
|
|
207
|
-
// MT: "EUR",
|
|
208
|
-
// MU: "MUR",
|
|
209
|
-
// MV: "MVR",
|
|
210
|
-
// MW: "MWK",
|
|
211
|
-
// MX: "MXN",
|
|
212
|
-
// MY: "MYR",
|
|
213
|
-
// MZ: "MZN",
|
|
214
|
-
// NA: "NAD",
|
|
215
|
-
// NC: "XPF",
|
|
216
|
-
// NE: "XOF",
|
|
217
|
-
// NF: "AUD",
|
|
218
|
-
// NG: "NGN",
|
|
219
|
-
// NI: "NIO",
|
|
220
|
-
// NL: "EUR",
|
|
221
|
-
// NO: "NOK",
|
|
222
|
-
// NP: "NPR",
|
|
223
|
-
// NR: "AUD",
|
|
224
|
-
// NU: "NZD",
|
|
225
|
-
// NZ: "NZD",
|
|
226
|
-
// OM: "OMR",
|
|
227
|
-
// PA: "PAB",
|
|
228
|
-
// PE: "PEN",
|
|
229
|
-
// PF: "XPF",
|
|
230
|
-
// PG: "PGK",
|
|
231
|
-
// PH: "PHP",
|
|
232
|
-
// PK: "PKR",
|
|
233
|
-
// PL: "PLN",
|
|
234
|
-
// PM: "EUR",
|
|
235
|
-
// PN: "NZD",
|
|
236
|
-
PR: "USD",
|
|
237
|
-
// PS: "ILS",
|
|
238
|
-
// PT: "EUR",
|
|
239
|
-
PW: "USD",
|
|
240
|
-
// PY: "PYG",
|
|
241
|
-
// QA: "QAR",
|
|
242
|
-
// RE: "EUR",
|
|
243
|
-
// RO: "RON",
|
|
244
|
-
// RS: "RSD",
|
|
245
|
-
// RU: "RUB",
|
|
246
|
-
// RW: "RWF",
|
|
247
|
-
// SA: "SAR",
|
|
248
|
-
// SB: "SBD",
|
|
249
|
-
// SC: "SCR",
|
|
250
|
-
// SD: "SDG",
|
|
251
|
-
// SE: "SEK",
|
|
252
|
-
// SG: "SGD",
|
|
253
|
-
// SH: "SHP",
|
|
254
|
-
// SI: "EUR",
|
|
255
|
-
// SJ: "NOK",
|
|
256
|
-
// SK: "EUR",
|
|
257
|
-
// SL: "SLL",
|
|
258
|
-
// SM: "EUR",
|
|
259
|
-
// SN: "XOF",
|
|
260
|
-
// SO: "SOS",
|
|
261
|
-
// SR: "SRD",
|
|
262
|
-
// ST: "STD",
|
|
263
|
-
// SV: "SVC",
|
|
264
|
-
// SX: "ANG",
|
|
265
|
-
// SY: "SYP",
|
|
266
|
-
// SZ: "SZL",
|
|
267
|
-
TC: "USD",
|
|
268
|
-
// TD: "XAF",
|
|
269
|
-
// TF: "EUR",
|
|
270
|
-
// TG: "XOF",
|
|
271
|
-
// TH: "THB",
|
|
272
|
-
// TJ: "TJS",
|
|
273
|
-
// TK: "NZD",
|
|
274
|
-
TL: "USD",
|
|
275
|
-
// TM: "TMT",
|
|
276
|
-
// TN: "TND",
|
|
277
|
-
// TO: "TOP",
|
|
278
|
-
// TR: "TRY",
|
|
279
|
-
// TT: "TTD",
|
|
280
|
-
// TV: "AUD",
|
|
281
|
-
// TW: "TWD",
|
|
282
|
-
// TZ: "TZS",
|
|
283
|
-
// UA: "UAH",
|
|
284
|
-
// UG: "UGX",
|
|
285
|
-
UM: "USD",
|
|
286
|
-
US: "USD",
|
|
287
|
-
// UY: "UYU",
|
|
288
|
-
// UZ: "UZS",
|
|
289
|
-
// VA: "EUR",
|
|
290
|
-
// VC: "XCD",
|
|
291
|
-
// VE: "VEF",
|
|
292
|
-
VG: "USD",
|
|
293
|
-
VI: "USD",
|
|
294
|
-
// VN: "VND",
|
|
295
|
-
// VU: "VUV",
|
|
296
|
-
// WF: "XPF",
|
|
297
|
-
// WS: "WST",
|
|
298
|
-
// YE: "YER",
|
|
299
|
-
// YT: "EUR",
|
|
300
|
-
// ZA: "ZAR",
|
|
301
|
-
// ZM: "ZMW",
|
|
302
|
-
// ZW: "ZWL",
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
function getCountryCode(localeString: string) {
|
|
306
|
-
let components = localeString.split("_");
|
|
307
|
-
if (components.length === 2) {
|
|
308
|
-
return components.pop() as string;
|
|
309
|
-
}
|
|
310
|
-
components = localeString.split("-");
|
|
311
|
-
if (components.length === 2) {
|
|
312
|
-
return components.pop() as string;
|
|
313
|
-
}
|
|
314
|
-
return localeString;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
function localeToCurrencyCode(locale: string): string {
|
|
318
|
-
const countryCode = getCountryCode(locale).toUpperCase() as CurrencyLocales;
|
|
319
|
-
if (countryCode in localeToCurrencyCodes) {
|
|
320
|
-
return localeToCurrencyCodes[countryCode];
|
|
321
|
-
}
|
|
322
|
-
return defaultCurrencyCode;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export const currentLocaleCurrencyCode = localeToCurrencyCode(
|
|
326
|
-
currentLocale as CurrencyLocales
|
|
327
|
-
);
|
|
328
|
-
|
|
329
|
-
// Will be returned in CurrencyAmount soon
|
|
330
|
-
export const btcPrice = 19500;
|
|
331
|
-
|
|
332
|
-
export function mapCurrencyAmount(currencyAmount: CurrencyAmount): CurrencyMap {
|
|
333
|
-
const { value, unit } = {
|
|
334
|
-
value: currencyAmount?.originalValue || 0,
|
|
335
|
-
unit: currencyAmount?.originalUnit || CurrencyUnit.SATOSHI,
|
|
336
|
-
};
|
|
337
|
-
let sats = value;
|
|
338
|
-
let msats = value * 1000;
|
|
339
|
-
let btc = value / 1e8;
|
|
340
|
-
let usd = round(btc * btcPrice, 2);
|
|
341
|
-
|
|
342
|
-
if (unit === CurrencyUnit.BITCOIN) {
|
|
343
|
-
sats = value * 1e8;
|
|
344
|
-
msats = value * 1e11;
|
|
345
|
-
btc = value;
|
|
346
|
-
usd = round(btc * btcPrice, 2);
|
|
347
|
-
} else if (unit === CurrencyUnit.MILLISATOSHI) {
|
|
348
|
-
sats = value / 1000;
|
|
349
|
-
msats = value;
|
|
350
|
-
btc = value / 1e11;
|
|
351
|
-
usd = round(btc * btcPrice, 2);
|
|
352
|
-
} else if (unit === CurrencyUnit.USD) {
|
|
353
|
-
usd = value;
|
|
354
|
-
btc = value / btcPrice;
|
|
355
|
-
sats = btc * 1e8;
|
|
356
|
-
msats = sats * 1000;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
const mapWithCurrencyUnits = {
|
|
360
|
-
[CurrencyUnit.BITCOIN]: btc,
|
|
361
|
-
[CurrencyUnit.SATOSHI]: sats,
|
|
362
|
-
[CurrencyUnit.FUTURE_VALUE]: sats,
|
|
363
|
-
[CurrencyUnit.MILLISATOSHI]: msats,
|
|
364
|
-
[CurrencyUnit.USD]: usd,
|
|
365
|
-
[CurrencyUnit.MICROBITCOIN]: 0,
|
|
366
|
-
[CurrencyUnit.MILLIBITCOIN]: 0,
|
|
367
|
-
[CurrencyUnit.NANOBITCOIN]: 0,
|
|
368
|
-
formatted: {
|
|
369
|
-
[CurrencyUnit.BITCOIN]: formatCurrencyStr({
|
|
370
|
-
value: btc,
|
|
371
|
-
unit: CurrencyUnit.BITCOIN,
|
|
372
|
-
}),
|
|
373
|
-
[CurrencyUnit.SATOSHI]: formatCurrencyStr({
|
|
374
|
-
value: sats,
|
|
375
|
-
unit: CurrencyUnit.SATOSHI,
|
|
376
|
-
}),
|
|
377
|
-
[CurrencyUnit.FUTURE_VALUE]: formatCurrencyStr({
|
|
378
|
-
value: sats,
|
|
379
|
-
unit: CurrencyUnit.SATOSHI,
|
|
380
|
-
}),
|
|
381
|
-
[CurrencyUnit.MILLISATOSHI]: formatCurrencyStr({
|
|
382
|
-
value: msats,
|
|
383
|
-
unit: CurrencyUnit.MILLISATOSHI,
|
|
384
|
-
}),
|
|
385
|
-
[CurrencyUnit.MICROBITCOIN]: "0",
|
|
386
|
-
[CurrencyUnit.MILLIBITCOIN]: "0",
|
|
387
|
-
[CurrencyUnit.NANOBITCOIN]: "0",
|
|
388
|
-
[CurrencyUnit.USD]: formatCurrencyStr({
|
|
389
|
-
value: usd,
|
|
390
|
-
unit: CurrencyUnit.USD,
|
|
391
|
-
}),
|
|
392
|
-
},
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
return {
|
|
396
|
-
...mapWithCurrencyUnits,
|
|
397
|
-
btc,
|
|
398
|
-
sats,
|
|
399
|
-
msats,
|
|
400
|
-
isZero: msats === 0,
|
|
401
|
-
isLessThan: (other: CurrencyMap) => msats < other.msats,
|
|
402
|
-
isGreaterThan: (other: CurrencyMap) => msats > other.msats,
|
|
403
|
-
isEqualTo: (other: CurrencyMap) => msats === other.msats,
|
|
404
|
-
formatted: {
|
|
405
|
-
...mapWithCurrencyUnits.formatted,
|
|
406
|
-
btc: mapWithCurrencyUnits.formatted[CurrencyUnit.BITCOIN],
|
|
407
|
-
sats: mapWithCurrencyUnits.formatted[CurrencyUnit.SATOSHI],
|
|
408
|
-
msats: mapWithCurrencyUnits.formatted[CurrencyUnit.MILLISATOSHI],
|
|
409
|
-
},
|
|
410
|
-
type: "CurrencyMap" as const,
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
export const isCurrencyMap = (currencyMap: any): currencyMap is CurrencyMap =>
|
|
415
|
-
currencyMap && currencyMap.type === "CurrencyMap";
|
|
416
|
-
|
|
417
|
-
export const abbrCurrencyUnit = (unit: CurrencyUnit) => {
|
|
418
|
-
switch (unit) {
|
|
419
|
-
case CurrencyUnit.BITCOIN:
|
|
420
|
-
return "BTC";
|
|
421
|
-
case CurrencyUnit.SATOSHI:
|
|
422
|
-
return "SAT";
|
|
423
|
-
case CurrencyUnit.MILLISATOSHI:
|
|
424
|
-
return "MSAT";
|
|
425
|
-
case CurrencyUnit.USD:
|
|
426
|
-
return "USD";
|
|
427
|
-
}
|
|
428
|
-
return "";
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
export function formatCurrencyStr(
|
|
432
|
-
amount: CurrencyAmountArg,
|
|
433
|
-
maxFractionDigits?: number,
|
|
434
|
-
compact?: boolean,
|
|
435
|
-
showBtcSymbol = false,
|
|
436
|
-
options: Intl.NumberFormatOptions = {}
|
|
437
|
-
) {
|
|
438
|
-
const num = typeof amount?.value === "number" ? amount.value : 0;
|
|
439
|
-
const unit = amount?.unit || CurrencyUnit.SATOSHI;
|
|
440
|
-
|
|
441
|
-
function getDefaultMaxFractionDigits(defaultDigits: number) {
|
|
442
|
-
return typeof maxFractionDigits === "undefined"
|
|
443
|
-
? compact
|
|
444
|
-
? 1
|
|
445
|
-
: defaultDigits
|
|
446
|
-
: maxFractionDigits;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// Symbol handled by toLocaleString for USD. These rely on the LightsparkIcons font
|
|
450
|
-
const symbol = !showBtcSymbol
|
|
451
|
-
? ""
|
|
452
|
-
: unit === CurrencyUnit.BITCOIN
|
|
453
|
-
? ""
|
|
454
|
-
: unit === CurrencyUnit.SATOSHI
|
|
455
|
-
? ""
|
|
456
|
-
: "";
|
|
457
|
-
|
|
458
|
-
switch (unit) {
|
|
459
|
-
case CurrencyUnit.BITCOIN:
|
|
460
|
-
case CurrencyUnit.MILLISATOSHI:
|
|
461
|
-
case CurrencyUnit.SATOSHI:
|
|
462
|
-
default:
|
|
463
|
-
return `${symbol}${num.toLocaleString(currentLocale, {
|
|
464
|
-
notation: compact ? ("compact" as const) : undefined,
|
|
465
|
-
maximumFractionDigits: getDefaultMaxFractionDigits(3),
|
|
466
|
-
...options,
|
|
467
|
-
})}`;
|
|
468
|
-
case CurrencyUnit.USD:
|
|
469
|
-
return num.toLocaleString(currentLocale, {
|
|
470
|
-
style: "currency",
|
|
471
|
-
currency: defaultCurrencyCode,
|
|
472
|
-
notation: compact ? ("compact" as const) : undefined,
|
|
473
|
-
maximumFractionDigits: getDefaultMaxFractionDigits(2),
|
|
474
|
-
...options,
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
function round(num: number, decimalPlaces = 0) {
|
|
480
|
-
var p = Math.pow(10, decimalPlaces);
|
|
481
|
-
var n = num * p * (1 + Number.EPSILON);
|
|
482
|
-
return Math.round(n) / p;
|
|
483
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es5",
|
|
4
|
-
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
-
"allowJs": true,
|
|
6
|
-
"skipLibCheck": true,
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"allowSyntheticDefaultImports": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"forceConsistentCasingInFileNames": true,
|
|
11
|
-
"noFallthroughCasesInSwitch": true,
|
|
12
|
-
"module": "esnext",
|
|
13
|
-
"moduleResolution": "node",
|
|
14
|
-
"resolveJsonModule": true,
|
|
15
|
-
"isolatedModules": true,
|
|
16
|
-
"noEmit": true,
|
|
17
|
-
"jsx": "react-jsx"
|
|
18
|
-
},
|
|
19
|
-
"include": ["src"]
|
|
20
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# Lightspark Streaming Wallet Extension
|
|
2
|
-
|
|
3
|
-
A simple demo Lightning wallet from Lightspark that demonstrates the power of streaming bitcoin while watching a video.
|
|
4
|
-
|
|
5
|
-
Navigate to "https://app.lightspark.com/demos/streaming" to try it out!
|
|
6
|
-
|
|
7
|
-
## Building
|
|
8
|
-
|
|
9
|
-
First build the JS sdk by running `npm install` then `npm run build` in the root of the js-sdk directory.
|
|
10
|
-
|
|
11
|
-
Then run those same commands in this directory to build the extension. It will output the compiled source to the `build`
|
|
12
|
-
directory.
|
|
13
|
-
|
|
14
|
-
## Installing from source
|
|
15
|
-
|
|
16
|
-
After building from source, navigate to `chrome://extensions` in Chrome and enable developer mode. Then click
|
|
17
|
-
"Load unpacked" and select the `streaming-wallet-extension/build` directory.
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const { whenDev } = require("@craco/craco");
|
|
2
|
-
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
webpack: {
|
|
6
|
-
plugins: {
|
|
7
|
-
add: [
|
|
8
|
-
new HtmlWebpackPlugin(
|
|
9
|
-
Object.assign(
|
|
10
|
-
{},
|
|
11
|
-
{
|
|
12
|
-
inject: true,
|
|
13
|
-
template: "./public/index.html",
|
|
14
|
-
excludeChunks: ["content", "background"],
|
|
15
|
-
},
|
|
16
|
-
whenDev(() => undefined, {
|
|
17
|
-
minify: {
|
|
18
|
-
removeComments: true,
|
|
19
|
-
collapseWhitespace: true,
|
|
20
|
-
removeRedundantAttributes: true,
|
|
21
|
-
useShortDoctype: true,
|
|
22
|
-
removeEmptyAttributes: true,
|
|
23
|
-
removeStyleLinkTypeAttributes: true,
|
|
24
|
-
keepClosingSlash: true,
|
|
25
|
-
minifyJS: true,
|
|
26
|
-
minifyCSS: true,
|
|
27
|
-
minifyURLs: true,
|
|
28
|
-
},
|
|
29
|
-
})
|
|
30
|
-
)
|
|
31
|
-
),
|
|
32
|
-
],
|
|
33
|
-
remove: ["HtmlWebpackPlugin"],
|
|
34
|
-
},
|
|
35
|
-
configure: (webpackConfig, { env, paths }) => {
|
|
36
|
-
return {
|
|
37
|
-
...webpackConfig,
|
|
38
|
-
entry: {
|
|
39
|
-
main: [
|
|
40
|
-
env === "development" &&
|
|
41
|
-
require.resolve("react-dev-utils/webpackHotDevClient"),
|
|
42
|
-
paths.appIndexJs,
|
|
43
|
-
].filter(Boolean),
|
|
44
|
-
content: "./src/contentscript/content.ts",
|
|
45
|
-
background: "./src/background/background.ts",
|
|
46
|
-
},
|
|
47
|
-
output: {
|
|
48
|
-
...webpackConfig.output,
|
|
49
|
-
filename: "static/js/[name].js",
|
|
50
|
-
},
|
|
51
|
-
optimization: {
|
|
52
|
-
...webpackConfig.optimization,
|
|
53
|
-
runtimeChunk: false,
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
};
|