@lightsparkdev/lightspark-sdk 0.1.6

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.
Files changed (223) hide show
  1. package/.fossa.yml +6 -0
  2. package/.prettierrc +1 -0
  3. package/.turbo/turbo-build.log +19 -0
  4. package/.turbo/turbo-lint.log +3 -0
  5. package/CHANGELOG.md +49 -0
  6. package/LICENSE +201 -0
  7. package/README.md +137 -0
  8. package/dist/Withdrawal-17e1c8af.d.ts +1672 -0
  9. package/dist/Withdrawal-27a4d10d.d.ts +1672 -0
  10. package/dist/chunk-3VRI7CHE.js +5508 -0
  11. package/dist/chunk-AGEUDR2V.js +4498 -0
  12. package/dist/chunk-N27QHRE4.js +5508 -0
  13. package/dist/client-3bba3f64.d.ts +1302 -0
  14. package/dist/index.cjs +6633 -0
  15. package/dist/index.d.ts +15 -0
  16. package/dist/index.js +1177 -0
  17. package/dist/objects/index.cjs +5347 -0
  18. package/dist/objects/index.d.ts +3 -0
  19. package/dist/objects/index.js +88 -0
  20. package/examples/node-scripts/authHelpers.ts +20 -0
  21. package/examples/node-scripts/createInvoice.ts +64 -0
  22. package/examples/node-scripts/example.ts +288 -0
  23. package/examples/node-scripts/getAccountDashboard.ts +24 -0
  24. package/examples/node-scripts/getNodeChannels.ts +34 -0
  25. package/examples/node-scripts/internalAuthHelpers.ts +26 -0
  26. package/examples/node-scripts/internal_example.ts +296 -0
  27. package/examples/node-scripts/package-lock.json +887 -0
  28. package/examples/node-scripts/package.json +22 -0
  29. package/examples/node-scripts/prettyPrintJsonForDocs.ts +62 -0
  30. package/examples/node-scripts/tsconfig.json +27 -0
  31. package/examples/oauth-example/README.md +19 -0
  32. package/examples/oauth-example/package-lock.json +16071 -0
  33. package/examples/oauth-example/package.json +50 -0
  34. package/examples/oauth-example/public/favicon.ico +0 -0
  35. package/examples/oauth-example/public/index.html +43 -0
  36. package/examples/oauth-example/public/logo192.png +0 -0
  37. package/examples/oauth-example/public/logo512.png +0 -0
  38. package/examples/oauth-example/public/manifest.json +25 -0
  39. package/examples/oauth-example/public/robots.txt +3 -0
  40. package/examples/oauth-example/src/App.css +7 -0
  41. package/examples/oauth-example/src/App.test.tsx +12 -0
  42. package/examples/oauth-example/src/App.tsx +16 -0
  43. package/examples/oauth-example/src/auth/AuthContext.ts +8 -0
  44. package/examples/oauth-example/src/auth/AuthProvider.tsx +44 -0
  45. package/examples/oauth-example/src/auth/RequireAuth.tsx +19 -0
  46. package/examples/oauth-example/src/auth/oauthProvider.ts +35 -0
  47. package/examples/oauth-example/src/components/Button.tsx +39 -0
  48. package/examples/oauth-example/src/components/CurrencyAmount.tsx +117 -0
  49. package/examples/oauth-example/src/components/Dashboard.tsx +158 -0
  50. package/examples/oauth-example/src/components/Table.tsx +22 -0
  51. package/examples/oauth-example/src/hooks/useAccountInfo.tsx +31 -0
  52. package/examples/oauth-example/src/icons/BitcoinB.tsx +20 -0
  53. package/examples/oauth-example/src/icons/Icon.tsx +121 -0
  54. package/examples/oauth-example/src/icons/Satoshi.tsx +28 -0
  55. package/examples/oauth-example/src/index.css +13 -0
  56. package/examples/oauth-example/src/index.tsx +23 -0
  57. package/examples/oauth-example/src/lightsparkclient/LightsparkClientContext.ts +10 -0
  58. package/examples/oauth-example/src/lightsparkclient/LightsparkClientProvider.tsx +53 -0
  59. package/examples/oauth-example/src/logo.svg +1 -0
  60. package/examples/oauth-example/src/pages/DashboardPage.tsx +71 -0
  61. package/examples/oauth-example/src/pages/LoginPage.tsx +63 -0
  62. package/examples/oauth-example/src/react-app-env.d.ts +1 -0
  63. package/examples/oauth-example/src/reportWebVitals.ts +15 -0
  64. package/examples/oauth-example/src/routes/index.tsx +15 -0
  65. package/examples/oauth-example/src/setupTests.ts +5 -0
  66. package/examples/oauth-example/src/utils/currency.ts +483 -0
  67. package/examples/oauth-example/tsconfig.json +20 -0
  68. package/examples/streaming-wallet-extension/.fossa.yml +6 -0
  69. package/examples/streaming-wallet-extension/README.md +17 -0
  70. package/examples/streaming-wallet-extension/craco.config.js +58 -0
  71. package/examples/streaming-wallet-extension/package-lock.json +18260 -0
  72. package/examples/streaming-wallet-extension/package.json +77 -0
  73. package/examples/streaming-wallet-extension/public/index.html +24 -0
  74. package/examples/streaming-wallet-extension/public/lightspark_full.png +0 -0
  75. package/examples/streaming-wallet-extension/public/lightspark_icon_circle.png +0 -0
  76. package/examples/streaming-wallet-extension/public/manifest.json +43 -0
  77. package/examples/streaming-wallet-extension/public/robots.txt +3 -0
  78. package/examples/streaming-wallet-extension/src/App.css +53 -0
  79. package/examples/streaming-wallet-extension/src/App.tsx +425 -0
  80. package/examples/streaming-wallet-extension/src/auth/AccountStorage.ts +28 -0
  81. package/examples/streaming-wallet-extension/src/auth/DemoAccountProvider.ts +99 -0
  82. package/examples/streaming-wallet-extension/src/auth/StreamingDemoCredentials.ts +10 -0
  83. package/examples/streaming-wallet-extension/src/background/PaymentStrategy.ts +36 -0
  84. package/examples/streaming-wallet-extension/src/background/PlaybackRange.ts +31 -0
  85. package/examples/streaming-wallet-extension/src/background/StreamingInvoiceHolder.ts +33 -0
  86. package/examples/streaming-wallet-extension/src/background/TransactionObserver.ts +66 -0
  87. package/examples/streaming-wallet-extension/src/background/VideoPlaybackRanges.ts +38 -0
  88. package/examples/streaming-wallet-extension/src/background/VideoProgressCache.ts +87 -0
  89. package/examples/streaming-wallet-extension/src/background/background.ts +145 -0
  90. package/examples/streaming-wallet-extension/src/background/messageHandling.ts +185 -0
  91. package/examples/streaming-wallet-extension/src/common/datetimes.ts +28 -0
  92. package/examples/streaming-wallet-extension/src/common/settings.ts +12 -0
  93. package/examples/streaming-wallet-extension/src/common/storage.ts +8 -0
  94. package/examples/streaming-wallet-extension/src/common/streamingTabs.ts +27 -0
  95. package/examples/streaming-wallet-extension/src/common/types.tsx +23 -0
  96. package/examples/streaming-wallet-extension/src/components/CirclePlusIcon.tsx +19 -0
  97. package/examples/streaming-wallet-extension/src/components/CurrencyAmount.tsx +110 -0
  98. package/examples/streaming-wallet-extension/src/components/CurrencyAmountRaw.tsx +195 -0
  99. package/examples/streaming-wallet-extension/src/components/LeftArrow.tsx +21 -0
  100. package/examples/streaming-wallet-extension/src/components/Loading.tsx +151 -0
  101. package/examples/streaming-wallet-extension/src/components/StreamingTransactionChip.tsx +95 -0
  102. package/examples/streaming-wallet-extension/src/components/TransactionRow.tsx +93 -0
  103. package/examples/streaming-wallet-extension/src/contentscript/content.ts +123 -0
  104. package/examples/streaming-wallet-extension/src/contentscript/lightsparkDemoDom.tsx +113 -0
  105. package/examples/streaming-wallet-extension/src/contentscript/videoElementParsers.ts +92 -0
  106. package/examples/streaming-wallet-extension/src/index.css +16 -0
  107. package/examples/streaming-wallet-extension/src/index.tsx +11 -0
  108. package/examples/streaming-wallet-extension/src/lightsparkClientProvider.tsx +26 -0
  109. package/examples/streaming-wallet-extension/src/react-app-env.d.ts +1 -0
  110. package/examples/streaming-wallet-extension/src/types/Messages.ts +17 -0
  111. package/examples/streaming-wallet-extension/tsconfig.json +20 -0
  112. package/package.json +87 -0
  113. package/src/auth/AccountTokenAuthProvider.ts +37 -0
  114. package/src/auth/index.ts +3 -0
  115. package/src/client.ts +759 -0
  116. package/src/graphql/BitcoinFeeEstimate.ts +13 -0
  117. package/src/graphql/CreateApiToken.ts +22 -0
  118. package/src/graphql/CreateInvoice.ts +18 -0
  119. package/src/graphql/CreateNodeWalletAddress.ts +13 -0
  120. package/src/graphql/CurrentAccount.ts +13 -0
  121. package/src/graphql/DecodeInvoice.ts +16 -0
  122. package/src/graphql/DeleteApiToken.ts +13 -0
  123. package/src/graphql/FundNode.ts +18 -0
  124. package/src/graphql/LightningFeeEstimateForInvoice.ts +21 -0
  125. package/src/graphql/LightningFeeEstimateForNode.ts +21 -0
  126. package/src/graphql/MultiNodeDashboard.ts +118 -0
  127. package/src/graphql/PayInvoice.ts +29 -0
  128. package/src/graphql/RecoverNodeSigningKey.ts +15 -0
  129. package/src/graphql/RequestWithdrawal.ts +25 -0
  130. package/src/graphql/SendPayment.ts +29 -0
  131. package/src/graphql/SingleNodeDashboard.ts +116 -0
  132. package/src/graphql/TransactionSubscription.ts +16 -0
  133. package/src/graphql/TransactionsForNode.ts +42 -0
  134. package/src/index.ts +5 -0
  135. package/src/objects/Account.ts +1222 -0
  136. package/src/objects/AccountToApiTokensConnection.ts +50 -0
  137. package/src/objects/AccountToChannelsConnection.ts +35 -0
  138. package/src/objects/AccountToNodesConnection.ts +62 -0
  139. package/src/objects/AccountToPaymentRequestsConnection.ts +50 -0
  140. package/src/objects/AccountToTransactionsConnection.ts +112 -0
  141. package/src/objects/ApiToken.ts +80 -0
  142. package/src/objects/BitcoinNetwork.ts +19 -0
  143. package/src/objects/BlockchainBalance.ts +102 -0
  144. package/src/objects/Channel.ts +283 -0
  145. package/src/objects/ChannelClosingTransaction.ts +150 -0
  146. package/src/objects/ChannelFees.ts +34 -0
  147. package/src/objects/ChannelOpeningTransaction.ts +150 -0
  148. package/src/objects/ChannelStatus.ts +25 -0
  149. package/src/objects/ChannelToTransactionsConnection.ts +86 -0
  150. package/src/objects/CreateApiTokenInput.ts +22 -0
  151. package/src/objects/CreateApiTokenOutput.ts +41 -0
  152. package/src/objects/CreateInvoiceInput.ts +27 -0
  153. package/src/objects/CreateInvoiceOutput.ts +21 -0
  154. package/src/objects/CreateNodeWalletAddressInput.ts +15 -0
  155. package/src/objects/CreateNodeWalletAddressOutput.ts +27 -0
  156. package/src/objects/CurrencyAmount.ts +55 -0
  157. package/src/objects/CurrencyUnit.ts +25 -0
  158. package/src/objects/DeleteApiTokenInput.ts +13 -0
  159. package/src/objects/DeleteApiTokenOutput.ts +23 -0
  160. package/src/objects/Deposit.ts +144 -0
  161. package/src/objects/Entity.ts +868 -0
  162. package/src/objects/FeeEstimate.ts +39 -0
  163. package/src/objects/FundNodeInput.ts +16 -0
  164. package/src/objects/FundNodeOutput.ts +28 -0
  165. package/src/objects/GraphNode.ts +110 -0
  166. package/src/objects/Hop.ts +108 -0
  167. package/src/objects/HtlcAttemptFailureCode.ts +65 -0
  168. package/src/objects/IncomingPayment.ts +141 -0
  169. package/src/objects/IncomingPaymentAttempt.ts +96 -0
  170. package/src/objects/IncomingPaymentAttemptStatus.ts +20 -0
  171. package/src/objects/IncomingPaymentToAttemptsConnection.ts +39 -0
  172. package/src/objects/Invoice.ts +226 -0
  173. package/src/objects/InvoiceData.ts +185 -0
  174. package/src/objects/InvoiceType.ts +15 -0
  175. package/src/objects/LightningFeeEstimateForInvoiceInput.ts +28 -0
  176. package/src/objects/LightningFeeEstimateForNodeInput.ts +25 -0
  177. package/src/objects/LightningFeeEstimateOutput.ts +33 -0
  178. package/src/objects/LightningTransaction.ts +393 -0
  179. package/src/objects/LightsparkNode.ts +377 -0
  180. package/src/objects/LightsparkNodePurpose.ts +17 -0
  181. package/src/objects/LightsparkNodeStatus.ts +29 -0
  182. package/src/objects/LightsparkNodeToChannelsConnection.ts +50 -0
  183. package/src/objects/Node.ts +273 -0
  184. package/src/objects/NodeAddress.ts +29 -0
  185. package/src/objects/NodeAddressType.ts +18 -0
  186. package/src/objects/NodeToAddressesConnection.ts +39 -0
  187. package/src/objects/OnChainTransaction.ts +318 -0
  188. package/src/objects/OutgoingPayment.ts +319 -0
  189. package/src/objects/OutgoingPaymentAttempt.ts +164 -0
  190. package/src/objects/OutgoingPaymentAttemptStatus.ts +18 -0
  191. package/src/objects/OutgoingPaymentAttemptToHopsConnection.ts +37 -0
  192. package/src/objects/OutgoingPaymentToAttemptsConnection.ts +39 -0
  193. package/src/objects/PageInfo.ts +31 -0
  194. package/src/objects/PayInvoiceInput.ts +33 -0
  195. package/src/objects/PayInvoiceOutput.ts +22 -0
  196. package/src/objects/PaymentFailureReason.ts +29 -0
  197. package/src/objects/PaymentRequest.ts +231 -0
  198. package/src/objects/PaymentRequestData.ts +183 -0
  199. package/src/objects/PaymentRequestStatus.ts +15 -0
  200. package/src/objects/Permission.ts +39 -0
  201. package/src/objects/RequestWithdrawalInput.ts +35 -0
  202. package/src/objects/RequestWithdrawalOutput.ts +24 -0
  203. package/src/objects/RichText.ts +19 -0
  204. package/src/objects/RoutingTransaction.ts +150 -0
  205. package/src/objects/RoutingTransactionFailureReason.ts +17 -0
  206. package/src/objects/Secret.ts +23 -0
  207. package/src/objects/SendPaymentInput.ts +30 -0
  208. package/src/objects/SendPaymentOutput.ts +22 -0
  209. package/src/objects/Transaction.ts +609 -0
  210. package/src/objects/TransactionFailures.ts +23 -0
  211. package/src/objects/TransactionStatus.ts +23 -0
  212. package/src/objects/TransactionType.ts +31 -0
  213. package/src/objects/TransactionUpdate.ts +67 -0
  214. package/src/objects/WalletDashboard.ts +32 -0
  215. package/src/objects/WebhookEventType.ts +15 -0
  216. package/src/objects/Withdrawal.ts +144 -0
  217. package/src/objects/WithdrawalMode.ts +15 -0
  218. package/src/objects/WithdrawalRequest.ts +224 -0
  219. package/src/objects/WithdrawalRequestStatus.ts +17 -0
  220. package/src/objects/WithdrawalRequestToChannelClosingTransactionsConnection.ts +57 -0
  221. package/src/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.ts +57 -0
  222. package/src/objects/index.ts +108 -0
  223. package/tsconfig.json +5 -0
@@ -0,0 +1,483 @@
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
+ }
@@ -0,0 +1,20 @@
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
+ }
@@ -0,0 +1,6 @@
1
+ version: 3
2
+
3
+ project:
4
+ id: lightspark/demo-chrome-ext
5
+ name: demo-chrome-ext
6
+ url: https://github.com/lightsparkdev/webdev
@@ -0,0 +1,17 @@
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.
@@ -0,0 +1,58 @@
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
+ };