Skip to content
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

feat: move nostr key to accounts #1964

Merged
merged 32 commits into from
Feb 1, 2023
Merged

feat: move nostr key to accounts #1964

merged 32 commits into from
Feb 1, 2023

Conversation

im-adithya
Copy link
Member

@im-adithya im-adithya commented Jan 11, 2023

Describe the changes you have made in this PR

This removes the nostr key in settings (which is being used globally across all accounts) and adds functionality for accounts to have nostr keys instead

Link this PR to an issue [optional]

Fixes #1934

Type of change

(Remove other not matching type)

  • feat: New feature (non-breaking change which adds functionality)

Screenshots of the changes [optional]

Account Page

Screenshot 2023-01-12 at 7 55 02 PM

Settings

Screenshot 2023-01-12 at 7 56 08 PM

Accounts Page

Screenshot 2023-01-12 at 7 57 20 PM

How has this been tested?

Tested manually

Checklist

  • My code follows the style guidelines of this project and performed a self-review of my own code
  • New and existing tests pass locally with my changes
  • I checked if I need to make corresponding changes to the documentation (and made those changes if needed)

@im-adithya
Copy link
Member Author

I left the nostr in the state itself as I got to know it's using the private key from outside, and the class is not initialized with the key. This reduces the work (and also doesn't make sense to include it in all accounts if it's anyways the same class)

@github-actions
Copy link

github-actions bot commented Jan 11, 2023

🚀 Thanks for the pull request!

Here are the current build files for testing:

Download and unzip the file for your browser. Refer to the readme for detailed install instructions.


This build is brought to you by: channel.ninja (who recently dropped 1000 sats):


Want to sponsor the next build? send some sats to ⚡️builds@getalby.com (don't forget to provide your name)

Don't forget: keep earning sats!

@im-adithya im-adithya marked this pull request as ready for review January 12, 2023 14:28
@escapedcat
Copy link
Contributor

escapedcat commented Jan 13, 2023

A unit-test is failing.

Look like I can't delete the nostr key? On master I can delete and after reload the field is still empty. Doesn't seem to work here.

On master I get the "use extension option":
image
image

Here I do not get this?:
image
image

Maybe I missed something? I reloaded the extension, had two accounts already added (test LND and albydev)

@im-adithya
Copy link
Member Author

Should work now!
Also, not sure why the unit test is failing, it's not translating the title it seems (but why?)

@@ -13,8 +13,20 @@ const defaultProps = {
};

const mockAccounts: Accounts = {
"1": { id: "1", connector: "lnd", config: "", name: "LND account" },
"2": { id: "2", connector: "galoy", config: "", name: "Galoy account" },
"1": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@escapedcat
Copy link
Contributor

Also, not sure why the unit test is failing, it's not translating the title it seems (but why?)

Maybe adding the i18nProvider helps, like we do here?:
https://github.com/getAlby/lightning-browser-extension/blob/task-nostr-account/src/app/components/AccountMenu/index.test.tsx/#L58-L60

Copy link
Collaborator

@bumi bumi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good progress! let's add some tests and then ship this!

src/app/screens/connectors/ConnectBtcpay/index.tsx Outdated Show resolved Hide resolved
src/types.ts Outdated Show resolved Hide resolved
@reneaaron
Copy link
Contributor

Just tested it, nice work! 💪

Here is some feedback on the UI:

Connector logo

Can we maybe use the connector logo here instead of the default avatar?
image

Alby lab

I think with this feature we can finally move Nostr out of the Lab status. Wdyt?
image

Export

The export icon isn't very intuitive. Can we at add an export label maybe?
image

Account name

Shouldn't the account name be reflected in the account select?
image

@im-adithya
Copy link
Member Author

[NEW!] Updated Nostr section

Screenshot 2023-01-20 at 4 32 03 PM

}

function generatePublicKey(priv: string) {
const nostr = new Nostr(priv);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be done via a msg.request... instead of importing Nostr from the background script?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nostr is just a utility class that is used to generate the public key from the private key. But you raised a good point. Maybe the Nostr class should be moved outside of the background-script folder. (maybe into src/common/utils?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should, we need some good folder structure. (I dislike "utils" because those are mostly bins for everything).

src/extension/background-script/actions/accounts/select.ts Outdated Show resolved Hide resolved
const account = accounts[id];
account.nostrPrivateKey = privateKey
? encryptData(privateKey, password)
: null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do a special "delete" action to remove the key and not do this by setting the private key to null. I would think that having a special key would prevent the user a bit better from accidentially deleting it.

src/extension/background-script/migrations/index.ts Outdated Show resolved Hide resolved
@bumi
Copy link
Collaborator

bumi commented Jan 29, 2023

  • back button (like on send/receive?)
  • save button on the name - to be consistent with the save button on the nostr key?
  • can we use a copy icon instead of the big button?
  • nostr public key must be displayed in the npub format
  • we have an accounts/index.tsx file should the show page be something like accounts/show.tsx
  • add Avvvatars - should this be part for the PublisherCard?
  • [ ]

@reneaaron
Copy link
Contributor

Since the avatars PR #1992 is now also merged, can we replace the default avatar on the detail page as well?

@escapedcat
Copy link
Contributor

escapedcat commented Feb 1, 2023

After manually saving a pasted private-key I get a blank screen:

nostr-manual-save.mov

Can you reproduce this?

image

After reloading the page everything is fine and the key is stored.

@im-adithya
Copy link
Member Author

Can you reproduce this?

Whoops! Did you use a "nsec" string? It expects a hex string as a private key. Not really sure if we should also accept "nsec" directly. (cc @bumi)

But yes, will be adding a toast to specify the requirement!

@escapedcat
Copy link
Contributor

Should this look like this in dark-mode?:
image

Copy link
Contributor

@escapedcat escapedcat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some minor comments

src/app/screens/Accounts/Show/index.tsx Show resolved Hide resolved
src/app/screens/Accounts/Show/index.tsx Show resolved Hide resolved
@bumi bumi merged commit 141fef9 into master Feb 1, 2023
@bumi bumi deleted the task-nostr-account branch February 1, 2023 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move nostr key to account
5 participants