@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,50 @@
1
+ {
2
+ "name": "lightspark-oauth-demo",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "dependencies": {
6
+ "@emotion/css": "^11.10.6",
7
+ "@emotion/react": "^11.10.6",
8
+ "@emotion/styled": "^11.10.6",
9
+ "@lightsparkdev/lightspark-sdk": "file:../../",
10
+ "@lightsparkdev/oauth": "file:../../../oauth",
11
+ "@testing-library/jest-dom": "^5.16.5",
12
+ "@testing-library/react": "^13.4.0",
13
+ "@testing-library/user-event": "^13.5.0",
14
+ "@types/jest": "^27.5.2",
15
+ "@types/node": "^16.18.16",
16
+ "@types/react": "^18.0.28",
17
+ "@types/react-dom": "^18.0.11",
18
+ "qrcode.react": "^3.1.0",
19
+ "react": "^18.2.0",
20
+ "react-dom": "^18.2.0",
21
+ "react-router-dom": "^6.9.0",
22
+ "react-scripts": "5.0.1",
23
+ "typescript": "^4.9.5",
24
+ "web-vitals": "^2.1.4"
25
+ },
26
+ "scripts": {
27
+ "start": "react-scripts start",
28
+ "build": "react-scripts build",
29
+ "test": "react-scripts test",
30
+ "eject": "react-scripts eject"
31
+ },
32
+ "eslintConfig": {
33
+ "extends": [
34
+ "react-app",
35
+ "react-app/jest"
36
+ ]
37
+ },
38
+ "browserslist": {
39
+ "production": [
40
+ ">0.2%",
41
+ "not dead",
42
+ "not op_mini all"
43
+ ],
44
+ "development": [
45
+ "last 1 chrome version",
46
+ "last 1 firefox version",
47
+ "last 1 safari version"
48
+ ]
49
+ }
50
+ }
@@ -0,0 +1,43 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <meta name="theme-color" content="#000000" />
8
+ <meta
9
+ name="description"
10
+ content="A demo of using oauth with the Lightspark JS SDK"
11
+ />
12
+ <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13
+ <!--
14
+ manifest.json provides metadata used when your web app is installed on a
15
+ user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16
+ -->
17
+ <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18
+ <!--
19
+ Notice the use of %PUBLIC_URL% in the tags above.
20
+ It will be replaced with the URL of the `public` folder during the build.
21
+ Only files inside the `public` folder can be referenced from the HTML.
22
+
23
+ Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24
+ work correctly both with client-side routing and a non-root public URL.
25
+ Learn how to configure a non-root public URL by running `npm run build`.
26
+ -->
27
+ <title>Lightspark OAuth Demo</title>
28
+ </head>
29
+ <body>
30
+ <noscript>You need to enable JavaScript to run this app.</noscript>
31
+ <div id="root"></div>
32
+ <!--
33
+ This HTML file is a template.
34
+ If you open it directly in the browser, you will see an empty page.
35
+
36
+ You can add webfonts, meta tags, or analytics to this file.
37
+ The build step will place the bundled scripts into the <body> tag.
38
+
39
+ To begin the development, run `npm start` or `yarn start`.
40
+ To create a production bundle, use `npm run build` or `yarn build`.
41
+ -->
42
+ </body>
43
+ </html>
@@ -0,0 +1,25 @@
1
+ {
2
+ "short_name": "React App",
3
+ "name": "Create React App Sample",
4
+ "icons": [
5
+ {
6
+ "src": "favicon.ico",
7
+ "sizes": "64x64 32x32 24x24 16x16",
8
+ "type": "image/x-icon"
9
+ },
10
+ {
11
+ "src": "logo192.png",
12
+ "type": "image/png",
13
+ "sizes": "192x192"
14
+ },
15
+ {
16
+ "src": "logo512.png",
17
+ "type": "image/png",
18
+ "sizes": "512x512"
19
+ }
20
+ ],
21
+ "start_url": ".",
22
+ "display": "standalone",
23
+ "theme_color": "#000000",
24
+ "background_color": "#ffffff"
25
+ }
@@ -0,0 +1,3 @@
1
+ # https://www.robotstxt.org/robotstxt.html
2
+ User-agent: *
3
+ Disallow:
@@ -0,0 +1,7 @@
1
+ .App {
2
+ display: flex;
3
+ max-width: 100%;
4
+ flex-direction: column;
5
+ align-items: center;
6
+ position: relative;
7
+ }
@@ -0,0 +1,12 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import App from "./App";
3
+
4
+ test("renders learn react link", () => {
5
+ render(
6
+ <App>
7
+ <div>test</div>
8
+ </App>
9
+ );
10
+ const linkElement = screen.getByText(/learn react/i);
11
+ expect(linkElement).toBeInTheDocument();
12
+ });
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ import "./App.css";
3
+ import AuthProvider from "./auth/AuthProvider";
4
+ import LightsparkClientProvider from "./lightsparkclient/LightsparkClientProvider";
5
+
6
+ function App(props: { children: React.ReactNode }) {
7
+ return (
8
+ <div className="App">
9
+ <LightsparkClientProvider>
10
+ <AuthProvider>{props.children}</AuthProvider>
11
+ </LightsparkClientProvider>
12
+ </div>
13
+ );
14
+ }
15
+
16
+ export default App;
@@ -0,0 +1,8 @@
1
+ interface AuthContextType {
2
+ signin: (callback: VoidFunction) => void;
3
+ signout: () => Promise<void>;
4
+ checkAuth: () => Promise<boolean>;
5
+ isAuthorized: () => boolean;
6
+ }
7
+
8
+ export default AuthContextType;
@@ -0,0 +1,44 @@
1
+ import { OAuthProvider as LsOauthProvider } from "@lightsparkdev/oauth";
2
+ import React, { useState } from "react";
3
+ import { useLightsparkClient } from "../lightsparkclient/LightsparkClientProvider";
4
+ import AuthContextType from "./AuthContext";
5
+ import { OAuthProvider } from "./oauthProvider";
6
+
7
+ const AuthContext = React.createContext<AuthContextType>(null!);
8
+
9
+ function AuthProvider({ children }: { children: React.ReactNode }) {
10
+ const [oauthProvider] = useState<OAuthProvider>(new OAuthProvider());
11
+ const clientProvider = useLightsparkClient();
12
+
13
+ const checkAuth = async () => {
14
+ if (await oauthProvider.checkAuth()) {
15
+ clientProvider.setAuthProvider(
16
+ new LsOauthProvider(oauthProvider.oauthHelper)
17
+ );
18
+ return true;
19
+ }
20
+ return false;
21
+ };
22
+
23
+ const signin = (callback: VoidFunction) => {
24
+ return oauthProvider.signin(callback);
25
+ };
26
+
27
+ const signout = () => {
28
+ return oauthProvider.signout();
29
+ };
30
+
31
+ const isAuthorized = () => {
32
+ return oauthProvider.isAuthorized();
33
+ };
34
+
35
+ const value = { signin, signout, checkAuth, isAuthorized };
36
+
37
+ return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
38
+ }
39
+
40
+ export function useAuth() {
41
+ return React.useContext(AuthContext);
42
+ }
43
+
44
+ export default AuthProvider;
@@ -0,0 +1,19 @@
1
+ import { Navigate, useLocation } from "react-router-dom";
2
+ import { useAuth } from "./AuthProvider";
3
+
4
+ function RequireAuth({ children }: { children: JSX.Element }) {
5
+ let auth = useAuth();
6
+ let location = useLocation();
7
+
8
+ if (!auth.isAuthorized()) {
9
+ // Redirect them to the /login page, but save the current location they were
10
+ // trying to go to when they were redirected. This allows us to send them
11
+ // along to that page after they login, which is a nicer user experience
12
+ // than dropping them off on the home page.
13
+ return <Navigate to="/login" state={{ from: location }} replace />;
14
+ }
15
+
16
+ return children;
17
+ }
18
+
19
+ export default RequireAuth;
@@ -0,0 +1,35 @@
1
+ import { OAuthStateHelper } from "@lightsparkdev/oauth";
2
+
3
+ const CLIENT_ID = "0186ffea-9d6e-7777-0000-8c584f503545";
4
+ const CLIENT_SECRET = "JrsBdKnPqLOPomGSXrGKFmS1YWuL8C77nxV1o8M5yEf";
5
+ const REDIRECT_URI =
6
+ window.location.href.substring(0, window.location.href.lastIndexOf("/")) +
7
+ "/oauth";
8
+
9
+ class OAuthProvider {
10
+ readonly oauthHelper = new OAuthStateHelper(
11
+ CLIENT_ID,
12
+ CLIENT_SECRET,
13
+ "dev.dev.sparkinfra.net",
14
+ "api.dev.dev.sparkinfra.net"
15
+ );
16
+
17
+ async checkAuth() {
18
+ await this.oauthHelper.checkForAuthorizationResponse();
19
+ return this.oauthHelper.isAuthorized();
20
+ }
21
+
22
+ signin(callback: VoidFunction) {
23
+ this.oauthHelper.launchOAuthFlow("all", REDIRECT_URI);
24
+ }
25
+
26
+ async signout() {
27
+ await this.oauthHelper.signOut();
28
+ }
29
+
30
+ isAuthorized() {
31
+ return this.oauthHelper.isAuthorized();
32
+ }
33
+ }
34
+
35
+ export { OAuthProvider };
@@ -0,0 +1,39 @@
1
+ import styled from "@emotion/styled";
2
+
3
+ export const UnstyledButton = styled.button`
4
+ appearance: none;
5
+ background: transparent;
6
+ border: none;
7
+ padding: 0;
8
+ cursor: ${({ disabled }) => (disabled ? "not-allowed" : "pointer")};
9
+ /* needed in Safari for some reason */
10
+ font-size: 1rem;
11
+ color: inherit;
12
+ font-weight: inherit;
13
+ `;
14
+
15
+ export const Button = styled(UnstyledButton)<{ primary?: boolean }>`
16
+ display: inline-flex;
17
+ opacity: ${({ disabled }) => (disabled ? 0.2 : 1)};
18
+ transition: opacity 0.2s;
19
+ position: relative;
20
+
21
+ color: ${({ primary }) => (primary ? "white" : "black")};
22
+ font-size: 14px;
23
+ font-weight: 600;
24
+
25
+ text-align: center;
26
+ white-space: nowrap;
27
+ background-color: ${({ primary }) => (primary ? "black" : "white")};
28
+ border: 1px solid black;
29
+ border-radius: 32px;
30
+ padding: 12px 24px;
31
+
32
+ &:hover {
33
+ opacity: 0.8;
34
+ }
35
+
36
+ &:active {
37
+ opacity: 0.6;
38
+ }
39
+ `;
@@ -0,0 +1,117 @@
1
+ // Copyright ©, 2022, Lightspark Group, Inc. - All Rights Reserved
2
+ import styled from "@emotion/styled/macro";
3
+ import {
4
+ CurrencyAmount as GraphQLCurrencyAmountType,
5
+ CurrencyUnit,
6
+ } from "@lightsparkdev/lightspark-sdk";
7
+ import { Icon } from "../icons/Icon";
8
+ import {
9
+ CurrencyMap,
10
+ formatCurrencyStr,
11
+ isCurrencyMap,
12
+ mapCurrencyAmount,
13
+ } from "../utils/currency";
14
+
15
+ type CurrencyAmountProps = {
16
+ amount: CurrencyAmountType | CurrencyMap;
17
+ displayUnit?: CurrencyUnit;
18
+ shortNumber?: boolean;
19
+ showUnits?: boolean;
20
+ ml?: number;
21
+ };
22
+
23
+ const CurrencyAmount = ({
24
+ amount,
25
+ displayUnit = CurrencyUnit.SATOSHI,
26
+ shortNumber,
27
+ showUnits = false,
28
+ ml = 0,
29
+ }: CurrencyAmountProps) => {
30
+ const amountMap = isCurrencyMap(amount) ? amount : mapCurrencyAmount(amount);
31
+ const value = amountMap[displayUnit] as number;
32
+ let formattedNumber = amountMap.formatted[displayUnit];
33
+ if (shortNumber) {
34
+ formattedNumber = formatCurrencyStr(
35
+ { value: Number(value), unit: displayUnit },
36
+ 1,
37
+ true
38
+ );
39
+ }
40
+ if (showUnits) {
41
+ formattedNumber += ` ${shorttext(displayUnit, value)}`;
42
+ }
43
+
44
+ return (
45
+ <StyledCurrencyAmount ml={ml}>
46
+ <CurrencyIcon unit={displayUnit} />
47
+ {formattedNumber}
48
+ </StyledCurrencyAmount>
49
+ );
50
+ };
51
+
52
+ export const CurrencyIcon = ({ unit }: { unit: CurrencyUnit }) => {
53
+ switch (unit) {
54
+ case CurrencyUnit.BITCOIN:
55
+ return <Icon name="BitcoinB" width={8} verticalAlign={-2} mr={2} />;
56
+ case CurrencyUnit.SATOSHI:
57
+ return <Icon name="Satoshi" width={8} verticalAlign={-2} mr={2} />;
58
+ default:
59
+ return null;
60
+ }
61
+ };
62
+
63
+ const shorttext = (unit: CurrencyUnit, value: number) => {
64
+ const pl = value !== 1;
65
+ switch (unit) {
66
+ case CurrencyUnit.BITCOIN:
67
+ return "BTC";
68
+ case CurrencyUnit.MILLIBITCOIN:
69
+ return "mBTC";
70
+ case CurrencyUnit.MICROBITCOIN:
71
+ return "μBTC";
72
+ case CurrencyUnit.SATOSHI:
73
+ return `sat${pl ? "s" : ""}`;
74
+ case CurrencyUnit.MILLISATOSHI:
75
+ return `msat${pl ? "s" : ""}`;
76
+ }
77
+ return unit;
78
+ };
79
+
80
+ const StyledCurrencyAmount = styled.span<{ ml: number }>`
81
+ color: inherit !important;
82
+ white-space: nowrap;
83
+ font-feature-settings: "tnum" on, "lnum" on;
84
+ margin-left: ${({ ml }) => ml}px;
85
+ `;
86
+
87
+ export class ConversionError {
88
+ message: string;
89
+
90
+ constructor(message: string) {
91
+ this.message = message;
92
+ }
93
+ }
94
+
95
+ export type CurrencyAmountType = Omit<
96
+ GraphQLCurrencyAmountType,
97
+ | "__typename"
98
+ | "original_value"
99
+ | "original_unit"
100
+ | "preferred_currency_value_rounded"
101
+ | "preferred_currency_value_approx"
102
+ | "preferred_currency_unit"
103
+ >;
104
+
105
+ export const valueAsSatoshis = (amount: CurrencyAmountType): number => {
106
+ switch (amount.originalUnit) {
107
+ case CurrencyUnit.BITCOIN:
108
+ return amount.originalValue * 1e8;
109
+ case CurrencyUnit.SATOSHI:
110
+ return amount.originalValue;
111
+ case CurrencyUnit.MILLISATOSHI:
112
+ return amount.originalValue * 0.001;
113
+ }
114
+ throw new ConversionError(`Cannot convert from {amount.unit} to Satoshis`);
115
+ };
116
+
117
+ export default CurrencyAmount;
@@ -0,0 +1,158 @@
1
+ import styled from "@emotion/styled";
2
+ import {
3
+ CurrencyAmount as CurrencyAmountType,
4
+ CurrencyUnit,
5
+ Transaction,
6
+ WalletDashboard,
7
+ } from "@lightsparkdev/lightspark-sdk";
8
+ import CurrencyAmount from "./CurrencyAmount";
9
+ import { Table, Td, Th, Tr } from "./Table";
10
+ import { Maybe } from "@lightsparkdev/core";
11
+
12
+ const Dashboard = ({ data }: { data: WalletDashboard }) => {
13
+ return (
14
+ <Container>
15
+ <Welcome>Welcome {data.displayName}!</Welcome>
16
+ <Subtitle>Your wallet's status is: {data.status}</Subtitle>
17
+ <AmountBar>
18
+ <AmountWithLabel
19
+ label="Confirmed L1 Balance"
20
+ amount={data.blockchainBalance?.confirmedBalance}
21
+ />
22
+ <AmountWithLabel
23
+ label="Total L1 Balance"
24
+ amount={data.blockchainBalance?.totalBalance}
25
+ />
26
+ <AmountWithLabel
27
+ label="Total Local Balance"
28
+ amount={data.totalLocalBalance}
29
+ />
30
+ <AmountWithLabel
31
+ label="Total Remote Balance"
32
+ amount={data.remoteBalance}
33
+ />
34
+ </AmountBar>
35
+ <TransactionTable transactions={data.recentTransactions} />
36
+ </Container>
37
+ );
38
+ };
39
+
40
+ const TransactionTable = ({
41
+ transactions,
42
+ }: {
43
+ transactions: Transaction[];
44
+ }) => {
45
+ return (
46
+ <Table style={{ marginTop: "32px" }}>
47
+ <thead>
48
+ <Tr>
49
+ <Th>Date</Th>
50
+ <Th>Type</Th>
51
+ <Th>Amount</Th>
52
+ <Th>Status</Th>
53
+ </Tr>
54
+ </thead>
55
+ <tbody>
56
+ {transactions.map((tx) => {
57
+ return (
58
+ <Tr key={tx.id}>
59
+ <Td>{new Date(tx.createdAt).toLocaleString()}</Td>
60
+ <Td>{tx.typename}</Td>
61
+ <Td>
62
+ <CurrencyAmount amount={tx.amount} />
63
+ </Td>
64
+ <Td>{tx.status}</Td>
65
+ </Tr>
66
+ );
67
+ })}
68
+ </tbody>
69
+ </Table>
70
+ );
71
+ };
72
+
73
+ const Container = styled.div`
74
+ display: flex;
75
+ flex-direction: column;
76
+ align-items: center;
77
+ justify-content: center;
78
+ margin: auto;
79
+ `;
80
+
81
+ const Welcome = styled.h1`
82
+ font-size: 24px;
83
+ font-weight: 700;
84
+ margin: 0;
85
+ `;
86
+
87
+ const Subtitle = styled.h2`
88
+ font-size: 16px;
89
+ font-weight: 500;
90
+ color: #666666;
91
+ margin-bottom: 32px;
92
+ margin-top: 8px;
93
+ `;
94
+
95
+ const AmountBar = styled.div`
96
+ display: flex;
97
+ flex-direction: row;
98
+ align-items: center;
99
+ justify-content: center;
100
+ gap: 24px;
101
+ `;
102
+
103
+ const AmountWithLabel = ({
104
+ label,
105
+ amount,
106
+ }: {
107
+ label: string;
108
+ amount: Maybe<CurrencyAmountType>;
109
+ }) => {
110
+ const amountOrZero = amount || {
111
+ originalValue: 0,
112
+ originalUnit: CurrencyUnit.SATOSHI,
113
+ preferredCurrencyValueRounded: 0,
114
+ preferredCurrencyValueApprox: 0,
115
+ preferredCurrencyUnit: CurrencyUnit.USD,
116
+ };
117
+ return (
118
+ <AmountWrapper>
119
+ <AmountLabel>{label}</AmountLabel>
120
+ <SatAmount>
121
+ <CurrencyAmount amount={amountOrZero} />
122
+ </SatAmount>
123
+ <UsdAmount>
124
+ Est. <CurrencyAmount amount={amountOrZero} displayUnit={CurrencyUnit.USD} />
125
+ </UsdAmount>
126
+ </AmountWrapper>
127
+ );
128
+ };
129
+
130
+ const AmountWrapper = styled.div`
131
+ display: flex;
132
+ flex-direction: column;
133
+ align-items: center;
134
+ justify-content: center;
135
+ padding: 8px;
136
+ border-radius: 8px;
137
+ border: 1px solid #e0e0e0;
138
+ background-color: #fafafa;
139
+ box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.08);
140
+ `;
141
+
142
+ const AmountLabel = styled.div`
143
+ font-size: 12px;
144
+ font-weight: 600;
145
+ margin-bottom: 4px;
146
+ `;
147
+
148
+ const SatAmount = styled.span`
149
+ font-size: 24px;
150
+ font-weight: 700;
151
+ margin-bottom: 4px;
152
+ `;
153
+
154
+ const UsdAmount = styled.span`
155
+ font-size: 12px;
156
+ `;
157
+
158
+ export default Dashboard;
@@ -0,0 +1,22 @@
1
+ import styled from "@emotion/styled";
2
+
3
+ export const Table = styled.table`
4
+ width: 100%;
5
+ border-collapse: collapse;
6
+ `;
7
+
8
+ export const Th = styled.th`
9
+ text-align: left;
10
+ padding: 8px;
11
+ border-bottom: 2px solid #ddd;
12
+ color: #2196f3;
13
+ `;
14
+
15
+ export const Td = styled.td`
16
+ text-align: left;
17
+ padding: 8px;
18
+ `;
19
+
20
+ export const Tr = styled.tr`
21
+ border-bottom: 1px solid #ddd;
22
+ `;
@@ -0,0 +1,31 @@
1
+ import { Account } from "@lightsparkdev/lightspark-sdk";
2
+ import { useEffect, useState } from "react";
3
+ import { useLightsparkClient } from "../lightsparkclient/LightsparkClientProvider";
4
+
5
+ const useAccountInfo = () => {
6
+ const clientProvider = useLightsparkClient();
7
+ const [account, setAccount] = useState<Account | null>(null);
8
+ const [nodeId, setNodeId] = useState<string | null>(null);
9
+
10
+ useEffect(() => {
11
+ clientProvider.isAuthenticated().then((isAuthed) => {
12
+ if (!isAuthed) {
13
+ return;
14
+ }
15
+ const client = clientProvider.getClient();
16
+ client.getCurrentAccount().then(async (account) => {
17
+ if (account) {
18
+ setAccount(account);
19
+ }
20
+
21
+ const nodes = await account?.getNodes(client);
22
+ const nodeId = nodes?.entities[0].id ?? null;
23
+ setNodeId(nodeId);
24
+ });
25
+ });
26
+ }, [clientProvider]);
27
+
28
+ return { account, nodeId };
29
+ };
30
+
31
+ export default useAccountInfo;
@@ -0,0 +1,20 @@
1
+ // Copyright ©, 2022, Lightspark Group, Inc. - All Rights Reserved
2
+
3
+ const BitcoinB = () => (
4
+ <svg
5
+ width="100%"
6
+ viewBox="0 0 9 13"
7
+ fill="none"
8
+ xmlns="http://www.w3.org/2000/svg"
9
+ >
10
+ <path
11
+ d="M2.52899 2.51568H1M2.52899 2.51568V6.30488M2.52899 2.51568H3.12195M2.52899 6.30488H6.25472M2.52899 6.30488V10.0941M6.25472 6.30488C7.61193 6.30488 8.42683 7.15312 8.42683 8.19948C8.42683 9.24584 7.61193 10.0941 6.25472 10.0941M6.25472 6.30488C7.61193 6.30488 8.42683 5.45664 8.42683 4.41028C8.42683 3.36392 7.61193 2.51568 6.25472 2.51568M6.25472 10.0941V11.875M6.25472 10.0941H3.12195M2.52899 10.0941H1M2.52899 10.0941H3.12195M6.25472 2.51568V1M6.25472 2.51568H3.12195M3.12195 1V2.51568M3.12195 10.0941V11.875"
12
+ stroke="currentColor"
13
+ strokeWidth="1.125"
14
+ strokeLinecap="round"
15
+ strokeLinejoin="round"
16
+ />
17
+ </svg>
18
+ );
19
+
20
+ export default BitcoinB;