@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.
- package/.fossa.yml +6 -0
- package/.prettierrc +1 -0
- package/.turbo/turbo-build.log +19 -0
- package/.turbo/turbo-lint.log +3 -0
- package/CHANGELOG.md +49 -0
- package/LICENSE +201 -0
- package/README.md +137 -0
- package/dist/Withdrawal-17e1c8af.d.ts +1672 -0
- package/dist/Withdrawal-27a4d10d.d.ts +1672 -0
- package/dist/chunk-3VRI7CHE.js +5508 -0
- package/dist/chunk-AGEUDR2V.js +4498 -0
- package/dist/chunk-N27QHRE4.js +5508 -0
- package/dist/client-3bba3f64.d.ts +1302 -0
- package/dist/index.cjs +6633 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +1177 -0
- package/dist/objects/index.cjs +5347 -0
- package/dist/objects/index.d.ts +3 -0
- package/dist/objects/index.js +88 -0
- package/examples/node-scripts/authHelpers.ts +20 -0
- package/examples/node-scripts/createInvoice.ts +64 -0
- package/examples/node-scripts/example.ts +288 -0
- package/examples/node-scripts/getAccountDashboard.ts +24 -0
- package/examples/node-scripts/getNodeChannels.ts +34 -0
- package/examples/node-scripts/internalAuthHelpers.ts +26 -0
- package/examples/node-scripts/internal_example.ts +296 -0
- package/examples/node-scripts/package-lock.json +887 -0
- package/examples/node-scripts/package.json +22 -0
- package/examples/node-scripts/prettyPrintJsonForDocs.ts +62 -0
- package/examples/node-scripts/tsconfig.json +27 -0
- package/examples/oauth-example/README.md +19 -0
- package/examples/oauth-example/package-lock.json +16071 -0
- package/examples/oauth-example/package.json +50 -0
- package/examples/oauth-example/public/favicon.ico +0 -0
- package/examples/oauth-example/public/index.html +43 -0
- 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 +25 -0
- package/examples/oauth-example/public/robots.txt +3 -0
- package/examples/oauth-example/src/App.css +7 -0
- package/examples/oauth-example/src/App.test.tsx +12 -0
- package/examples/oauth-example/src/App.tsx +16 -0
- package/examples/oauth-example/src/auth/AuthContext.ts +8 -0
- package/examples/oauth-example/src/auth/AuthProvider.tsx +44 -0
- package/examples/oauth-example/src/auth/RequireAuth.tsx +19 -0
- package/examples/oauth-example/src/auth/oauthProvider.ts +35 -0
- package/examples/oauth-example/src/components/Button.tsx +39 -0
- package/examples/oauth-example/src/components/CurrencyAmount.tsx +117 -0
- package/examples/oauth-example/src/components/Dashboard.tsx +158 -0
- package/examples/oauth-example/src/components/Table.tsx +22 -0
- package/examples/oauth-example/src/hooks/useAccountInfo.tsx +31 -0
- package/examples/oauth-example/src/icons/BitcoinB.tsx +20 -0
- package/examples/oauth-example/src/icons/Icon.tsx +121 -0
- package/examples/oauth-example/src/icons/Satoshi.tsx +28 -0
- package/examples/oauth-example/src/index.css +13 -0
- package/examples/oauth-example/src/index.tsx +23 -0
- package/examples/oauth-example/src/lightsparkclient/LightsparkClientContext.ts +10 -0
- package/examples/oauth-example/src/lightsparkclient/LightsparkClientProvider.tsx +53 -0
- package/examples/oauth-example/src/logo.svg +1 -0
- package/examples/oauth-example/src/pages/DashboardPage.tsx +71 -0
- package/examples/oauth-example/src/pages/LoginPage.tsx +63 -0
- package/examples/oauth-example/src/react-app-env.d.ts +1 -0
- package/examples/oauth-example/src/reportWebVitals.ts +15 -0
- package/examples/oauth-example/src/routes/index.tsx +15 -0
- package/examples/oauth-example/src/setupTests.ts +5 -0
- package/examples/oauth-example/src/utils/currency.ts +483 -0
- package/examples/oauth-example/tsconfig.json +20 -0
- package/examples/streaming-wallet-extension/.fossa.yml +6 -0
- package/examples/streaming-wallet-extension/README.md +17 -0
- package/examples/streaming-wallet-extension/craco.config.js +58 -0
- package/examples/streaming-wallet-extension/package-lock.json +18260 -0
- package/examples/streaming-wallet-extension/package.json +77 -0
- package/examples/streaming-wallet-extension/public/index.html +24 -0
- 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 +43 -0
- package/examples/streaming-wallet-extension/public/robots.txt +3 -0
- package/examples/streaming-wallet-extension/src/App.css +53 -0
- package/examples/streaming-wallet-extension/src/App.tsx +425 -0
- package/examples/streaming-wallet-extension/src/auth/AccountStorage.ts +28 -0
- package/examples/streaming-wallet-extension/src/auth/DemoAccountProvider.ts +99 -0
- package/examples/streaming-wallet-extension/src/auth/StreamingDemoCredentials.ts +10 -0
- package/examples/streaming-wallet-extension/src/background/PaymentStrategy.ts +36 -0
- package/examples/streaming-wallet-extension/src/background/PlaybackRange.ts +31 -0
- package/examples/streaming-wallet-extension/src/background/StreamingInvoiceHolder.ts +33 -0
- package/examples/streaming-wallet-extension/src/background/TransactionObserver.ts +66 -0
- package/examples/streaming-wallet-extension/src/background/VideoPlaybackRanges.ts +38 -0
- package/examples/streaming-wallet-extension/src/background/VideoProgressCache.ts +87 -0
- package/examples/streaming-wallet-extension/src/background/background.ts +145 -0
- package/examples/streaming-wallet-extension/src/background/messageHandling.ts +185 -0
- package/examples/streaming-wallet-extension/src/common/datetimes.ts +28 -0
- package/examples/streaming-wallet-extension/src/common/settings.ts +12 -0
- package/examples/streaming-wallet-extension/src/common/storage.ts +8 -0
- package/examples/streaming-wallet-extension/src/common/streamingTabs.ts +27 -0
- package/examples/streaming-wallet-extension/src/common/types.tsx +23 -0
- package/examples/streaming-wallet-extension/src/components/CirclePlusIcon.tsx +19 -0
- package/examples/streaming-wallet-extension/src/components/CurrencyAmount.tsx +110 -0
- package/examples/streaming-wallet-extension/src/components/CurrencyAmountRaw.tsx +195 -0
- package/examples/streaming-wallet-extension/src/components/LeftArrow.tsx +21 -0
- package/examples/streaming-wallet-extension/src/components/Loading.tsx +151 -0
- package/examples/streaming-wallet-extension/src/components/StreamingTransactionChip.tsx +95 -0
- package/examples/streaming-wallet-extension/src/components/TransactionRow.tsx +93 -0
- package/examples/streaming-wallet-extension/src/contentscript/content.ts +123 -0
- package/examples/streaming-wallet-extension/src/contentscript/lightsparkDemoDom.tsx +113 -0
- package/examples/streaming-wallet-extension/src/contentscript/videoElementParsers.ts +92 -0
- package/examples/streaming-wallet-extension/src/index.css +16 -0
- package/examples/streaming-wallet-extension/src/index.tsx +11 -0
- package/examples/streaming-wallet-extension/src/lightsparkClientProvider.tsx +26 -0
- package/examples/streaming-wallet-extension/src/react-app-env.d.ts +1 -0
- package/examples/streaming-wallet-extension/src/types/Messages.ts +17 -0
- package/examples/streaming-wallet-extension/tsconfig.json +20 -0
- package/package.json +87 -0
- package/src/auth/AccountTokenAuthProvider.ts +37 -0
- package/src/auth/index.ts +3 -0
- package/src/client.ts +759 -0
- package/src/graphql/BitcoinFeeEstimate.ts +13 -0
- package/src/graphql/CreateApiToken.ts +22 -0
- package/src/graphql/CreateInvoice.ts +18 -0
- package/src/graphql/CreateNodeWalletAddress.ts +13 -0
- package/src/graphql/CurrentAccount.ts +13 -0
- package/src/graphql/DecodeInvoice.ts +16 -0
- package/src/graphql/DeleteApiToken.ts +13 -0
- package/src/graphql/FundNode.ts +18 -0
- package/src/graphql/LightningFeeEstimateForInvoice.ts +21 -0
- package/src/graphql/LightningFeeEstimateForNode.ts +21 -0
- package/src/graphql/MultiNodeDashboard.ts +118 -0
- package/src/graphql/PayInvoice.ts +29 -0
- package/src/graphql/RecoverNodeSigningKey.ts +15 -0
- package/src/graphql/RequestWithdrawal.ts +25 -0
- package/src/graphql/SendPayment.ts +29 -0
- package/src/graphql/SingleNodeDashboard.ts +116 -0
- package/src/graphql/TransactionSubscription.ts +16 -0
- package/src/graphql/TransactionsForNode.ts +42 -0
- package/src/index.ts +5 -0
- package/src/objects/Account.ts +1222 -0
- package/src/objects/AccountToApiTokensConnection.ts +50 -0
- package/src/objects/AccountToChannelsConnection.ts +35 -0
- package/src/objects/AccountToNodesConnection.ts +62 -0
- package/src/objects/AccountToPaymentRequestsConnection.ts +50 -0
- package/src/objects/AccountToTransactionsConnection.ts +112 -0
- package/src/objects/ApiToken.ts +80 -0
- package/src/objects/BitcoinNetwork.ts +19 -0
- package/src/objects/BlockchainBalance.ts +102 -0
- package/src/objects/Channel.ts +283 -0
- package/src/objects/ChannelClosingTransaction.ts +150 -0
- package/src/objects/ChannelFees.ts +34 -0
- package/src/objects/ChannelOpeningTransaction.ts +150 -0
- package/src/objects/ChannelStatus.ts +25 -0
- package/src/objects/ChannelToTransactionsConnection.ts +86 -0
- package/src/objects/CreateApiTokenInput.ts +22 -0
- package/src/objects/CreateApiTokenOutput.ts +41 -0
- package/src/objects/CreateInvoiceInput.ts +27 -0
- package/src/objects/CreateInvoiceOutput.ts +21 -0
- package/src/objects/CreateNodeWalletAddressInput.ts +15 -0
- package/src/objects/CreateNodeWalletAddressOutput.ts +27 -0
- package/src/objects/CurrencyAmount.ts +55 -0
- package/src/objects/CurrencyUnit.ts +25 -0
- package/src/objects/DeleteApiTokenInput.ts +13 -0
- package/src/objects/DeleteApiTokenOutput.ts +23 -0
- package/src/objects/Deposit.ts +144 -0
- package/src/objects/Entity.ts +868 -0
- package/src/objects/FeeEstimate.ts +39 -0
- package/src/objects/FundNodeInput.ts +16 -0
- package/src/objects/FundNodeOutput.ts +28 -0
- package/src/objects/GraphNode.ts +110 -0
- package/src/objects/Hop.ts +108 -0
- package/src/objects/HtlcAttemptFailureCode.ts +65 -0
- package/src/objects/IncomingPayment.ts +141 -0
- package/src/objects/IncomingPaymentAttempt.ts +96 -0
- package/src/objects/IncomingPaymentAttemptStatus.ts +20 -0
- package/src/objects/IncomingPaymentToAttemptsConnection.ts +39 -0
- package/src/objects/Invoice.ts +226 -0
- package/src/objects/InvoiceData.ts +185 -0
- package/src/objects/InvoiceType.ts +15 -0
- package/src/objects/LightningFeeEstimateForInvoiceInput.ts +28 -0
- package/src/objects/LightningFeeEstimateForNodeInput.ts +25 -0
- package/src/objects/LightningFeeEstimateOutput.ts +33 -0
- package/src/objects/LightningTransaction.ts +393 -0
- package/src/objects/LightsparkNode.ts +377 -0
- package/src/objects/LightsparkNodePurpose.ts +17 -0
- package/src/objects/LightsparkNodeStatus.ts +29 -0
- package/src/objects/LightsparkNodeToChannelsConnection.ts +50 -0
- package/src/objects/Node.ts +273 -0
- package/src/objects/NodeAddress.ts +29 -0
- package/src/objects/NodeAddressType.ts +18 -0
- package/src/objects/NodeToAddressesConnection.ts +39 -0
- package/src/objects/OnChainTransaction.ts +318 -0
- package/src/objects/OutgoingPayment.ts +319 -0
- package/src/objects/OutgoingPaymentAttempt.ts +164 -0
- package/src/objects/OutgoingPaymentAttemptStatus.ts +18 -0
- package/src/objects/OutgoingPaymentAttemptToHopsConnection.ts +37 -0
- package/src/objects/OutgoingPaymentToAttemptsConnection.ts +39 -0
- package/src/objects/PageInfo.ts +31 -0
- package/src/objects/PayInvoiceInput.ts +33 -0
- package/src/objects/PayInvoiceOutput.ts +22 -0
- package/src/objects/PaymentFailureReason.ts +29 -0
- package/src/objects/PaymentRequest.ts +231 -0
- package/src/objects/PaymentRequestData.ts +183 -0
- package/src/objects/PaymentRequestStatus.ts +15 -0
- package/src/objects/Permission.ts +39 -0
- package/src/objects/RequestWithdrawalInput.ts +35 -0
- package/src/objects/RequestWithdrawalOutput.ts +24 -0
- package/src/objects/RichText.ts +19 -0
- package/src/objects/RoutingTransaction.ts +150 -0
- package/src/objects/RoutingTransactionFailureReason.ts +17 -0
- package/src/objects/Secret.ts +23 -0
- package/src/objects/SendPaymentInput.ts +30 -0
- package/src/objects/SendPaymentOutput.ts +22 -0
- package/src/objects/Transaction.ts +609 -0
- package/src/objects/TransactionFailures.ts +23 -0
- package/src/objects/TransactionStatus.ts +23 -0
- package/src/objects/TransactionType.ts +31 -0
- package/src/objects/TransactionUpdate.ts +67 -0
- package/src/objects/WalletDashboard.ts +32 -0
- package/src/objects/WebhookEventType.ts +15 -0
- package/src/objects/Withdrawal.ts +144 -0
- package/src/objects/WithdrawalMode.ts +15 -0
- package/src/objects/WithdrawalRequest.ts +224 -0
- package/src/objects/WithdrawalRequestStatus.ts +17 -0
- package/src/objects/WithdrawalRequestToChannelClosingTransactionsConnection.ts +57 -0
- package/src/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.ts +57 -0
- package/src/objects/index.ts +108 -0
- package/tsconfig.json +5 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import styled from "@emotion/styled/macro";
|
|
2
|
+
import { useLayoutEffect, useState } from "react";
|
|
3
|
+
|
|
4
|
+
const rootFontSizePx = 12;
|
|
5
|
+
|
|
6
|
+
function isString(str: unknown): str is string {
|
|
7
|
+
return typeof str === "string";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type Component = () => JSX.Element;
|
|
11
|
+
|
|
12
|
+
type IconMap = {
|
|
13
|
+
[key: string]: Component;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const iconMap: IconMap = {};
|
|
17
|
+
|
|
18
|
+
async function loadIcon(iconName: string) {
|
|
19
|
+
let IconComp;
|
|
20
|
+
try {
|
|
21
|
+
({ default: IconComp } = await import(
|
|
22
|
+
// this can't be a variable only, needs to have some string constraints:
|
|
23
|
+
`./${iconName}.tsx`
|
|
24
|
+
));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
throw new Error(`Icon ${iconName} not found`);
|
|
27
|
+
}
|
|
28
|
+
iconMap[iconName] = IconComp as Component;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type IconProps = {
|
|
32
|
+
className?: string;
|
|
33
|
+
name: string;
|
|
34
|
+
width: number;
|
|
35
|
+
mr?: number;
|
|
36
|
+
ml?: number;
|
|
37
|
+
verticalAlign?: "middle" | "top" | "bottom" | "super" | number;
|
|
38
|
+
color?: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const defaultProps = {
|
|
42
|
+
verticalAlign: "middle" as const,
|
|
43
|
+
mr: 0,
|
|
44
|
+
ml: 0,
|
|
45
|
+
color: undefined,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export function Icon({
|
|
49
|
+
className,
|
|
50
|
+
name,
|
|
51
|
+
width,
|
|
52
|
+
mr = defaultProps.mr,
|
|
53
|
+
ml = defaultProps.ml,
|
|
54
|
+
verticalAlign = defaultProps.verticalAlign,
|
|
55
|
+
color = defaultProps.color,
|
|
56
|
+
}: IconProps) {
|
|
57
|
+
const [, setLoading] = useState(false);
|
|
58
|
+
|
|
59
|
+
const IconComponent = iconMap[name] || null;
|
|
60
|
+
|
|
61
|
+
useLayoutEffect(() => {
|
|
62
|
+
(async () => {
|
|
63
|
+
if (!iconMap[name]) {
|
|
64
|
+
setLoading(true);
|
|
65
|
+
await loadIcon(name);
|
|
66
|
+
setLoading(false);
|
|
67
|
+
}
|
|
68
|
+
})();
|
|
69
|
+
}, [name]);
|
|
70
|
+
|
|
71
|
+
// Assume width is px relative to the root font size but specify in ems to preserve scale for larger font sizes
|
|
72
|
+
const w = parseFloat((width / rootFontSizePx).toFixed(2));
|
|
73
|
+
const mrRems = parseFloat((mr / rootFontSizePx).toFixed(2));
|
|
74
|
+
const mlRems = parseFloat((ml / rootFontSizePx).toFixed(2));
|
|
75
|
+
const va =
|
|
76
|
+
typeof verticalAlign === "string"
|
|
77
|
+
? verticalAlign
|
|
78
|
+
: parseFloat((verticalAlign / rootFontSizePx).toFixed(2));
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<IconContainer
|
|
82
|
+
className={className}
|
|
83
|
+
w={w}
|
|
84
|
+
mr={mrRems}
|
|
85
|
+
ml={mlRems}
|
|
86
|
+
verticalAlign={va}
|
|
87
|
+
fontColor={color}
|
|
88
|
+
>
|
|
89
|
+
{IconComponent ? <IconComponent /> : null}
|
|
90
|
+
</IconContainer>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
Icon.defaultProps = defaultProps;
|
|
95
|
+
|
|
96
|
+
type IconContainerProps = {
|
|
97
|
+
w: number;
|
|
98
|
+
mr: number;
|
|
99
|
+
ml: number;
|
|
100
|
+
verticalAlign: string | number;
|
|
101
|
+
fontColor?: string;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const IconContainer = styled.span<IconContainerProps>`
|
|
105
|
+
pointer-events: none;
|
|
106
|
+
display: inline-flex;
|
|
107
|
+
${({ mr, ml, w }) => `
|
|
108
|
+
width: ${w}em;
|
|
109
|
+
${mr ? `margin-right: ${mr}em;` : ""}
|
|
110
|
+
${ml ? `margin-left: ${ml}em;` : ""}
|
|
111
|
+
`}
|
|
112
|
+
|
|
113
|
+
vertical-align: ${({ verticalAlign }) =>
|
|
114
|
+
isString(verticalAlign) ? verticalAlign : `${verticalAlign}em`};
|
|
115
|
+
|
|
116
|
+
${({ fontColor, theme }) => `
|
|
117
|
+
& svg {
|
|
118
|
+
color: ${fontColor || "inherit"};
|
|
119
|
+
}
|
|
120
|
+
`}
|
|
121
|
+
`;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright ©, 2022, Lightspark Group, Inc. - All Rights Reserved
|
|
2
|
+
|
|
3
|
+
function Satoshi() {
|
|
4
|
+
return (
|
|
5
|
+
<svg
|
|
6
|
+
width="100%"
|
|
7
|
+
viewBox="0 0 26 41"
|
|
8
|
+
fill="none"
|
|
9
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
10
|
+
>
|
|
11
|
+
<path d="M0 11.2142H26" stroke="currentColor" strokeWidth="3.71429" />
|
|
12
|
+
<path
|
|
13
|
+
d="M13 5.64284V0.0714111"
|
|
14
|
+
stroke="currentColor"
|
|
15
|
+
strokeWidth="3.71429"
|
|
16
|
+
/>
|
|
17
|
+
<path
|
|
18
|
+
d="M13 40.9286V35.3572"
|
|
19
|
+
stroke="currentColor"
|
|
20
|
+
strokeWidth="3.71429"
|
|
21
|
+
/>
|
|
22
|
+
<path d="M0 20.5H26" stroke="currentColor" strokeWidth="3.71429" />
|
|
23
|
+
<path d="M0 29.7858H26" stroke="currentColor" strokeWidth="3.71429" />
|
|
24
|
+
</svg>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default Satoshi;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
body {
|
|
2
|
+
margin: 0;
|
|
3
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
|
|
4
|
+
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
|
|
5
|
+
sans-serif;
|
|
6
|
+
-webkit-font-smoothing: antialiased;
|
|
7
|
+
-moz-osx-font-smoothing: grayscale;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
code {
|
|
11
|
+
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
|
|
12
|
+
monospace;
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import ReactDOM from "react-dom/client";
|
|
3
|
+
import { BrowserRouter } from "react-router-dom";
|
|
4
|
+
import App from "./App";
|
|
5
|
+
import "./index.css";
|
|
6
|
+
import reportWebVitals from "./reportWebVitals";
|
|
7
|
+
import routes from "./routes";
|
|
8
|
+
|
|
9
|
+
const root = ReactDOM.createRoot(
|
|
10
|
+
document.getElementById("root") as HTMLElement
|
|
11
|
+
);
|
|
12
|
+
root.render(
|
|
13
|
+
<React.StrictMode>
|
|
14
|
+
<BrowserRouter basename={process.env.PUBLIC_URL}>
|
|
15
|
+
<App>{routes}</App>
|
|
16
|
+
</BrowserRouter>
|
|
17
|
+
</React.StrictMode>
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
// If you want to start measuring performance in your app, pass a function
|
|
21
|
+
// to log results (for example: reportWebVitals(console.log))
|
|
22
|
+
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
|
23
|
+
reportWebVitals();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthProvider } from "@lightsparkdev/core";
|
|
2
|
+
import { LightsparkClient } from "@lightsparkdev/lightspark-sdk";
|
|
3
|
+
|
|
4
|
+
interface LightsparkClientContextType {
|
|
5
|
+
getClient: () => LightsparkClient;
|
|
6
|
+
setAuthProvider: (provider: AuthProvider) => void;
|
|
7
|
+
isAuthenticated: () => Promise<boolean>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default LightsparkClientContextType;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AuthProvider } from "@lightsparkdev/core";
|
|
2
|
+
import { LightsparkClient } from "@lightsparkdev/lightspark-sdk";
|
|
3
|
+
import React, { useState } from "react";
|
|
4
|
+
import LightsparkClientContextType from "./LightsparkClientContext";
|
|
5
|
+
|
|
6
|
+
let LightsparkClientContext = React.createContext<LightsparkClientContextType>(
|
|
7
|
+
null!
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
function LightsparkClientProvider({ children }: { children: React.ReactNode }) {
|
|
11
|
+
const [client, setClient] = useState<LightsparkClient | null>(null);
|
|
12
|
+
|
|
13
|
+
const getClient = () => {
|
|
14
|
+
if (!client) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
"LightsparkClient not initialized. Set an auth provider before using the client."
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return client;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const isAuthenticated = () => {
|
|
24
|
+
if (!client) {
|
|
25
|
+
return Promise.resolve(false);
|
|
26
|
+
}
|
|
27
|
+
return client.isAuthorized();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const setAuthProvider = (authProvider: AuthProvider) => {
|
|
31
|
+
if (!client) {
|
|
32
|
+
setClient(
|
|
33
|
+
new LightsparkClient(authProvider, "api.dev.dev.sparkinfra.net")
|
|
34
|
+
);
|
|
35
|
+
} else {
|
|
36
|
+
client.setAuthProvider(authProvider);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let value = { getClient, setAuthProvider, isAuthenticated };
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<LightsparkClientContext.Provider value={value}>
|
|
44
|
+
{children}
|
|
45
|
+
</LightsparkClientContext.Provider>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function useLightsparkClient() {
|
|
50
|
+
return React.useContext(LightsparkClientContext);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export default LightsparkClientProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import styled from "@emotion/styled";
|
|
2
|
+
import { BitcoinNetwork, WalletDashboard } from "@lightsparkdev/lightspark-sdk";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { useAuth } from "../auth/AuthProvider";
|
|
5
|
+
import RequireAuth from "../auth/RequireAuth";
|
|
6
|
+
import { Button } from "../components/Button";
|
|
7
|
+
import Dashboard from "../components/Dashboard";
|
|
8
|
+
import useAccountInfo from "../hooks/useAccountInfo";
|
|
9
|
+
import { useLightsparkClient } from "../lightsparkclient/LightsparkClientProvider";
|
|
10
|
+
|
|
11
|
+
function DashboardPage() {
|
|
12
|
+
const [loading, setLoading] = useState<boolean>(true);
|
|
13
|
+
const { account, nodeId } = useAccountInfo();
|
|
14
|
+
const clientProvider = useLightsparkClient();
|
|
15
|
+
const [dashboard, setDashboard] = useState<WalletDashboard>();
|
|
16
|
+
const auth = useAuth();
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!account || !nodeId) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const client = clientProvider.getClient();
|
|
23
|
+
client
|
|
24
|
+
.getSingleNodeDashboard(nodeId, BitcoinNetwork.REGTEST)
|
|
25
|
+
.then((dashboard) => {
|
|
26
|
+
setDashboard(dashboard);
|
|
27
|
+
})
|
|
28
|
+
.catch((err) => {
|
|
29
|
+
console.log(err);
|
|
30
|
+
})
|
|
31
|
+
.finally(() => {
|
|
32
|
+
setLoading(false);
|
|
33
|
+
});
|
|
34
|
+
}, [account, clientProvider, nodeId]);
|
|
35
|
+
|
|
36
|
+
let content;
|
|
37
|
+
if (loading) {
|
|
38
|
+
content = <div>Loading...</div>;
|
|
39
|
+
} else if (!dashboard) {
|
|
40
|
+
content = <div>Something went wrong :-(</div>;
|
|
41
|
+
} else {
|
|
42
|
+
content = (
|
|
43
|
+
<div>
|
|
44
|
+
<Header>
|
|
45
|
+
<Button
|
|
46
|
+
primary
|
|
47
|
+
onClick={() => {
|
|
48
|
+
auth.signout();
|
|
49
|
+
}}
|
|
50
|
+
>
|
|
51
|
+
Sign out
|
|
52
|
+
</Button>
|
|
53
|
+
</Header>
|
|
54
|
+
<Dashboard data={dashboard} />
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return <RequireAuth>{content}</RequireAuth>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const Header = styled.div`
|
|
63
|
+
display: flex;
|
|
64
|
+
justify-content: end;
|
|
65
|
+
align-items: center;
|
|
66
|
+
width: 100%;
|
|
67
|
+
max-width: 800px;
|
|
68
|
+
padding: 16px;
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
export default DashboardPage;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import styled from "@emotion/styled";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { useLocation, useNavigate } from "react-router-dom";
|
|
4
|
+
import { useAuth } from "../auth/AuthProvider";
|
|
5
|
+
import { Button } from "../components/Button";
|
|
6
|
+
|
|
7
|
+
const LoginPage = () => {
|
|
8
|
+
const navigate = useNavigate();
|
|
9
|
+
const location = useLocation();
|
|
10
|
+
const auth = useAuth();
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (window.location.search.includes("code")) {
|
|
14
|
+
const queryString = window.location.search.substring(1); // includes '?'
|
|
15
|
+
const path = ["/oauth", queryString].join("#");
|
|
16
|
+
navigate(path);
|
|
17
|
+
}
|
|
18
|
+
auth.checkAuth().then((isAuthorized: boolean) => {
|
|
19
|
+
if (isAuthorized) {
|
|
20
|
+
navigate("/");
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}, [auth, navigate]);
|
|
24
|
+
|
|
25
|
+
const from = location.state?.from?.pathname || "/";
|
|
26
|
+
|
|
27
|
+
function handleLogin() {
|
|
28
|
+
auth.signin(() => {
|
|
29
|
+
// Send them back to the page they tried to visit when they were
|
|
30
|
+
// redirected to the login page. Use { replace: true } so we don't create
|
|
31
|
+
// another entry in the history stack for the login page. This means that
|
|
32
|
+
// when they get to the protected page and click the back button, they
|
|
33
|
+
// won't end up back on the login page, which is also really nice for the
|
|
34
|
+
// user experience.
|
|
35
|
+
navigate(from, { replace: true });
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Container>
|
|
41
|
+
<Description>Log into your Lightspark account to continue</Description>
|
|
42
|
+
<Button primary onClick={handleLogin}>
|
|
43
|
+
Login
|
|
44
|
+
</Button>
|
|
45
|
+
</Container>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const Description = styled.p`
|
|
50
|
+
font-size: 20px;
|
|
51
|
+
text-align: center;
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
const Container = styled.div`
|
|
55
|
+
display: flex;
|
|
56
|
+
flex-direction: column;
|
|
57
|
+
align-items: center;
|
|
58
|
+
justify-content: center;
|
|
59
|
+
margin: auto;
|
|
60
|
+
height: 100vh;
|
|
61
|
+
`;
|
|
62
|
+
|
|
63
|
+
export default LoginPage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="react-scripts" />
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReportHandler } from "web-vitals";
|
|
2
|
+
|
|
3
|
+
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
|
|
4
|
+
if (onPerfEntry && onPerfEntry instanceof Function) {
|
|
5
|
+
import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
|
6
|
+
getCLS(onPerfEntry);
|
|
7
|
+
getFID(onPerfEntry);
|
|
8
|
+
getFCP(onPerfEntry);
|
|
9
|
+
getLCP(onPerfEntry);
|
|
10
|
+
getTTFB(onPerfEntry);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default reportWebVitals;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Route, Routes } from "react-router-dom";
|
|
2
|
+
import DashboardPage from "../pages/DashboardPage";
|
|
3
|
+
import LoginPage from "../pages/LoginPage";
|
|
4
|
+
|
|
5
|
+
const routes = (
|
|
6
|
+
<>
|
|
7
|
+
<Routes>
|
|
8
|
+
<Route path="/" element={<DashboardPage />} />
|
|
9
|
+
<Route path="/login" element={<LoginPage />} />
|
|
10
|
+
<Route path="/oauth" element={<LoginPage />} />
|
|
11
|
+
</Routes>
|
|
12
|
+
</>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export default routes;
|