-
Notifications
You must be signed in to change notification settings - Fork 208
Feat: Add Spark connector #3437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rolznz
wants to merge
14
commits into
master
Choose a base branch
from
feat/spark
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4c12f94
feat: add spark connector (spark init failing)
rolznz 43e9127
fix: add chunkLoading: false to avoid dynamic loading of imports
rolznz 52d34d9
feat: use account mnemonic, implement spark (pay, receive, check paym…
rolznz 3a482a9
feat: mnemonic generation flow for spark
pavanjoshi914 6be962e
feat: add sign message method
pavanjoshi914 7d6751d
Merge pull request #3434 from getAlby/mnemonic-generation-flow
rolznz 491950a
feat: spark ui updates
pavanjoshi914 ee1ad61
feat: update logo
pavanjoshi914 e1d9055
feat: add experimental warning
pavanjoshi914 25faa20
Merge branch 'master' into feat/spark
pavanjoshi914 b5645f2
feat: reiterate through key encryption and generation flow
pavanjoshi914 aec712c
Merge branch 'feat/spark' of https://github.com/getAlby/lightning-bro…
pavanjoshi914 a59af2c
chore: refactor
pavanjoshi914 ebf02e6
Merge remote-tracking branch 'upstream/master' into feat/spark
pavanjoshi914 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import ConnectorForm from "@components/ConnectorForm"; | ||
| import ConnectionErrorToast from "@components/toasts/ConnectionErrorToast"; | ||
| import { useState } from "react"; | ||
| import { Trans, useTranslation } from "react-i18next"; | ||
| import { useNavigate } from "react-router-dom"; | ||
| import toast from "~/app/components/Toast"; | ||
| import msg from "~/common/lib/msg"; | ||
|
|
||
| import Alert from "~/app/components/Alert"; | ||
| import api from "~/common/lib/api"; | ||
| import logo from "/static/assets/icons/spark.png"; | ||
|
|
||
| export default function ConnectSpark() { | ||
| const navigate = useNavigate(); | ||
| const { t } = useTranslation("translation", { | ||
| keyPrefix: "choose_connector.spark", | ||
| }); | ||
| const [loading, setLoading] = useState(false); | ||
|
|
||
| function getConnectorType() { | ||
| return "spark"; | ||
| } | ||
|
|
||
| async function handleSubmit(event: React.FormEvent<HTMLFormElement>) { | ||
| event.preventDefault(); | ||
| setLoading(true); | ||
|
|
||
| const mnemonic = await api.generateMnemonic(); | ||
| const encryptedMnemonic = await api.encryptValue(mnemonic); | ||
|
|
||
| const nostrPrivateKey = await api.nostr.generatePrivateKey( | ||
| undefined, | ||
| mnemonic | ||
| ); | ||
|
|
||
| const encryptedNostrPrivateKey = await api.encryptValue(nostrPrivateKey); | ||
| const account = { | ||
| name: "Spark", | ||
| config: {}, | ||
| connector: getConnectorType(), | ||
| mnemonic: encryptedMnemonic, | ||
| useMnemonicForLnurlAuth: true, | ||
| nostrPrivateKey: encryptedNostrPrivateKey, | ||
| hasImportedNostrKey: false, | ||
| }; | ||
|
|
||
| try { | ||
| const validation = await msg.request("validateAccount", account); | ||
| if (validation.valid) { | ||
| const addResult = await msg.request("addAccount", account); | ||
| if (addResult.accountId) { | ||
| await msg.request("selectAccount", { | ||
| id: addResult.accountId, | ||
| }); | ||
| navigate("/test-connection"); | ||
| } | ||
| } else { | ||
| console.error(validation); | ||
| toast.error( | ||
| <ConnectionErrorToast message={validation.error as string} /> | ||
| ); | ||
| } | ||
| } catch (e) { | ||
| console.error(e); | ||
| let message = t("page.errors.connection_failed"); | ||
| if (e instanceof Error) { | ||
| message += `\n\n${e.message}`; | ||
| } | ||
| toast.error(message); | ||
| } | ||
| setLoading(false); | ||
| } | ||
|
|
||
| return ( | ||
| <ConnectorForm | ||
| title={ | ||
| <h1 className="text-2xl font-bold dark:text-white"> | ||
| <Trans i18nKey={"title"} t={t} /> | ||
| </h1> | ||
| } | ||
| description={ | ||
| <Trans | ||
| i18nKey={"page.instructions"} | ||
| t={t} | ||
| components={[ | ||
| // eslint-disable-next-line react/jsx-key | ||
| <a | ||
| target="_blank" | ||
| rel="noreferrer" | ||
| className="underline" | ||
| href="https://www.spark.money/" | ||
| ></a>, | ||
| ]} | ||
| /> | ||
| } | ||
| logo={logo} | ||
| submitLoading={loading} | ||
| onSubmit={handleSubmit} | ||
| > | ||
| <Alert type="warn"> | ||
| <Trans | ||
| i18nKey={"page.warning"} | ||
| t={t} | ||
| components={[ | ||
| // eslint-disable-next-line react/jsx-key | ||
| <a | ||
| target="_blank" | ||
| rel="noreferrer" | ||
| className="underline" | ||
| href="https://docs.spark.money/wallet/developer-guide/unilateral-exit" | ||
| ></a>, | ||
| ]} | ||
| /> | ||
| </Alert> | ||
| </ConnectorForm> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/extension/background-script/actions/setup/encryptValue.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { encryptData } from "~/common/lib/crypto"; | ||
|
|
||
| import { MessageValueEncrypt } from "~/types"; | ||
| import state from "../../state"; | ||
|
|
||
| const encryptValue = async (message: MessageValueEncrypt) => { | ||
| const password = await state.getState().password(); | ||
| if (!password) { | ||
| return { | ||
| error: "Password is missing.", | ||
| }; | ||
| } | ||
| let value = message.args.value; | ||
| value = encryptData(value, password); | ||
| return { | ||
| data: value, | ||
| }; | ||
| }; | ||
|
|
||
| export default encryptValue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,16 @@ | ||
| import encryptValue from "./encryptValue"; | ||
| import reset from "./reset"; | ||
| import { setIcon, setIconMessageHandler } from "./setIcon"; | ||
| import setPassword from "./setPassword"; | ||
| import status from "./status"; | ||
| import validateAccount from "./validateAccount"; | ||
|
|
||
| export { | ||
| setPassword, | ||
| status, | ||
| encryptValue, | ||
| reset, | ||
| validateAccount, | ||
| setIcon, | ||
| setIconMessageHandler, | ||
| setPassword, | ||
| status, | ||
| validateAccount, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just wondering if this is the best approach since we add more complexity to these functions to both handle accounts and non-accounts.
But I can't see any other way except actually creating the account before we validate it 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
creating account before validating will go totally opposite to the existing flows that we have for other connectors. instead its better to handle this at script level
it just generates key in two way. either getting mnemonic from account id or if its passed explicitly. i guess this is more better to do somehow