Skip to content

Commit

Permalink
V1 (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
motorina0 authored Nov 6, 2024
1 parent 2020bd9 commit de7fe05
Show file tree
Hide file tree
Showing 52 changed files with 6,679 additions and 3,115 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ __pycache__
htmlcov
test-reports
tests/data/*.sqlite3
node_modules

*.swo
*.swp
Expand Down
14 changes: 14 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
**/.git
**/.svn
**/.hg
**/node_modules

*.yml

**/static/market/*
**/static/js/nostr.bundle.js*


flake.lock

.venv
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"semi": false,
"arrowParens": "avoid",
"insertPragma": false,
"printWidth": 80,
"proseWrap": "preserve",
"singleQuote": true,
"trailingComma": "none",
"useTabs": false,
"bracketSameLine": false,
"bracketSpacing": false
}
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
all: format check

format: prettier black ruff

check: mypy pyright checkblack checkruff checkprettier

prettier:
poetry run ./node_modules/.bin/prettier --write .
pyright:
poetry run ./node_modules/.bin/pyright

mypy:
poetry run mypy .

black:
poetry run black .

ruff:
poetry run ruff check . --fix

checkruff:
poetry run ruff check .

checkprettier:
poetry run ./node_modules/.bin/prettier --check .

checkblack:
poetry run black --check .

checkeditorconfig:
editorconfig-checker

test:
PYTHONUNBUFFERED=1 \
DEBUG=true \
poetry run pytest
install-pre-commit-hook:
@echo "Installing pre-commit hook to git"
@echo "Uninstall the hook with poetry run pre-commit uninstall"
poetry run pre-commit install

pre-commit:
poetry run pre-commit run --all-files


checkbundle:
@echo "skipping checkbundle"
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Nostr Market ([NIP-15](https://github.com/nostr-protocol/nips/blob/master/15.md)) - <small>[LNbits](https://github.com/lnbits/lnbits) extension</small>
<small>For more about LNBits extension check [this tutorial](https://github.com/lnbits/lnbits/wiki/LNbits-Extensions).</small>

<small>For more about LNBits extension check [this tutorial](https://github.com/lnbits/lnbits/wiki/LNbits-Extensions).</small>

**Demo at Nostrica <a href="https://www.youtube.com/live/2NueacYJovA?feature=share&t=6846">here</a>**.

**Original protocol for [Diagon Alley](https://github.com/lnbits/Diagon-Alley) (resilient marketplaces)**

> The concepts around resilience in Diagon Alley helped influence the creation of the NOSTR protocol, now we get to build Diagon Alley on NOSTR!

## Prerequisites

This extension uses the LNbits [nostrclient](https://github.com/lnbits/nostrclient) extension, an extension that makes _nostrfying_ other extensions easy.
![image](https://user-images.githubusercontent.com/2951406/236773044-81d3f30b-1ce7-4c5d-bdaf-b4a80ddddc58.png)

- before you continue, please make sure that [nostrclient](https://github.com/lnbits/nostrclient) extension is installed, activated and correctly configured.
- [nostrclient](https://github.com/lnbits/nostrclient) is usually installed as admin-only extension, so if you do not have admin access please ask an admin to confirm that [nostrclient](https://github.com/lnbits/nostrclient) is OK.
- see the [Troubleshoot](https://github.com/lnbits/nostrclient#troubleshoot) section for more details on how to check the health of `nostrclient` extension


## Create, or import, a merchant account

As a merchant you need to provide a Nostr key pair, or the extension can generate one for you.
Expand Down Expand Up @@ -97,44 +97,48 @@ Make sure to add your `merchant` public key to the list:
![image](https://user-images.githubusercontent.com/2951406/236787686-0e300c0a-eb5d-4490-aa70-568738ac78f4.png)

### Styling

In order to create a customized Marketplace, we use `naddr` as defined in [NIP-19](https://github.com/nostr-protocol/nips/blob/master/19.md#shareable-identifiers-with-extra-metadata). You must create an event (kind: `30019`) that has all the custom properties, including merchants and relays, of your marketplace. Start by going to the marketplace page:
![vanilla market](https://i.imgur.com/nCaMh1N.png)

You'll need to Login, and head over to *Marketplace Info*. Optionally import some merchants and relays, that will be included in the event. Click on *Edit* and fill out your marketplace custom info:
You'll need to Login, and head over to _Marketplace Info_. Optionally import some merchants and relays, that will be included in the event. Click on _Edit_ and fill out your marketplace custom info:
![edit](https://i.imgur.com/wEuHuN9.png)

Fill in the optional fields:

- Add a name to the Marketplace
- Add a small description
- Add a logo image URL
- Add a banner image URL (max height: 250px)
- Choose a theme
- Choose a theme

By clicking *Publish*, a `kind: 30019` event will be sent to the defined relays containing all the information about your custom Marketplace. On the left drawer, a button with *Copy Naddr* will show up.
By clicking _Publish_, a `kind: 30019` event will be sent to the defined relays containing all the information about your custom Marketplace. On the left drawer, a button with _Copy Naddr_ will show up.
![copy naddr](https://i.imgur.com/VuNIMVf.png)

You can then share your Marketplace, with the merchants and relays, banner, and style by using that Nostr identifier. The URL for the marketplace will be for example: `https://legend.lnbits.com/nostrmarket/market?naddr=naddr1qqfy6ctjddjhgurvv93k....`, you need to include the URL parameter `naddr=<your naddr>`. When a user visits that URL, the client will get the `30019` event and configure the Marketplace to what you defined. In the example bellow, a couple of merchants, relays, `autumn` theme, name (*Veggies Market*) and a header banner:
You can then share your Marketplace, with the merchants and relays, banner, and style by using that Nostr identifier. The URL for the marketplace will be for example: `https://legend.lnbits.com/nostrmarket/market?naddr=naddr1qqfy6ctjddjhgurvv93k....`, you need to include the URL parameter `naddr=<your naddr>`. When a user visits that URL, the client will get the `30019` event and configure the Marketplace to what you defined. In the example bellow, a couple of merchants, relays, `autumn` theme, name (_Veggies Market_) and a header banner:
![final](https://i.imgur.com/EYG7vYS.png)

The nostr event is a replaceable event, so you can change it to what you like and publish a new one to replace a previous one. For example adding a new merchant, or remove, change theme, add more relays,e tc...


## Troubleshoot

### Check communication with Nostr

In order to test that the integration with Nostr is working fine, one can add an `npub` to the chat box and check that DMs are working as expected:

https://user-images.githubusercontent.com/2951406/236777983-259f81d8-136f-48b3-bb73-80749819b5f9.mov

### Restart connection to Nostr

If the communication with Nostr is not working then an admin user can `Restart` the Nostr connection.

Merchants can afterwards re-publish their products.

https://user-images.githubusercontent.com/2951406/236778651-7ada9f6d-07a1-491c-ac9c-55530326c32a.mp4

### Check Nostrclient extension
- see the [Troubleshoot](https://github.com/lnbits/nostrclient#troubleshoot) section for more details on how to check the health of `nostrclient` extension

- see the [Troubleshoot](https://github.com/lnbits/nostrclient#troubleshoot) section for more details on how to check the health of `nostrclient` extension

## Aditional info

Expand Down
19 changes: 12 additions & 7 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import asyncio

from fastapi import APIRouter
from loguru import logger

from lnbits.db import Database
from lnbits.helpers import template_renderer
from lnbits.tasks import create_permanent_unique_task
from loguru import logger

from .nostr.nostr_client import NostrClient

Expand All @@ -24,14 +23,14 @@
def nostrmarket_renderer():
return template_renderer(["nostrmarket/templates"])


nostr_client: NostrClient = NostrClient()


from .tasks import wait_for_nostr_events, wait_for_paid_invoices
from .tasks import wait_for_nostr_events, wait_for_paid_invoices # noqa
from .views import * # noqa
from .views_api import * # noqa


scheduled_tasks: list[asyncio.Task] = []


Expand All @@ -57,7 +56,13 @@ async def _wait_for_nostr_events():
await asyncio.sleep(15)
await wait_for_nostr_events(nostr_client)

task1 = create_permanent_unique_task("ext_nostrmarket_paid_invoices", wait_for_paid_invoices)
task2 = create_permanent_unique_task("ext_nostrmarket_subscribe_to_nostr_client", _subscribe_to_nostr_client)
task3 = create_permanent_unique_task("ext_nostrmarket_wait_for_events", _wait_for_nostr_events)
task1 = create_permanent_unique_task(
"ext_nostrmarket_paid_invoices", wait_for_paid_invoices
)
task2 = create_permanent_unique_task(
"ext_nostrmarket_subscribe_to_nostr_client", _subscribe_to_nostr_client
)
task3 = create_permanent_unique_task(
"ext_nostrmarket_wait_for_events", _wait_for_nostr_events
)
scheduled_tasks.extend([task1, task2, task3])
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Nostr Market",
"short_description": "Nostr Webshop/market on LNbits",
"tile": "/nostrmarket/static/images/bitcoin-shop.png",
"min_lnbits_version": "0.12.6",
"min_lnbits_version": "1.0.0",
"contributors": [
{
"name": "motorina0",
Expand Down
Loading

0 comments on commit de7fe05

Please sign in to comment.