Skip to content

Commit

Permalink
Merge pull request #6 from lnbits/add_name_prop
Browse files Browse the repository at this point in the history
allow name without extra splits
  • Loading branch information
motorina0 authored Oct 19, 2023
2 parents 255f20e + 64bfcf2 commit 01323f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@ The TipJar extension allows you to integrate Bitcoin Lightning (and on-chain) ti
<h2>How to set it up</h2>

1. Simply create a new Tip Jar with the desired details (onchain and webhook optional):
![image](https://user-images.githubusercontent.com/28876473/134996842-ec2f2783-2eef-4671-8eaf-023713865512.png)
![image](https://user-images.githubusercontent.com/28876473/134996842-ec2f2783-2eef-4671-8eaf-023713865512.png)
1. Share the URL you get from this little button:
![image](https://user-images.githubusercontent.com/28876473/134996973-f8ed4632-ea2f-4b62-83f1-1e4c6b6c91fa.png)

<h2>A note on webhooks</h3>

The `description` field of the message POSTed to your webhook will be in the following format:
* `{length of the name}|{name}{message}`

You can split along the first `|`. This will give you the index at which to split between the name of the tipper and the message of the tipper.
![image](https://user-images.githubusercontent.com/28876473/134996973-f8ed4632-ea2f-4b62-83f1-1e4c6b6c91fa.png)

<h3>And that's it already! Let the sats flow!</h3>
14 changes: 4 additions & 10 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ async def api_create_tip(data: createTips):
if not name:
name = "Anonymous"

# Ensure that description string can be split reliably
description = f"{len(name)}|{name}{message}"
charge_id = await create_charge(
data={
"amount": sats,
"webhook": tipjar.webhook or "",
"description": description,
"name": name,
"description": message,
"onchainwallet": tipjar.onchain or "",
"lnbitswallet": tipjar.wallet,
"completelink": "/tipjar/" + str(tipjar_id),
Expand Down Expand Up @@ -136,7 +135,6 @@ async def api_update_tip(
)

if tip.wallet != wallet.wallet.id:

raise HTTPException(
status_code=HTTPStatus.FORBIDDEN, detail="Not your tip."
)
Expand Down Expand Up @@ -178,9 +176,7 @@ async def api_update_tipjar(


@tipjar_ext.delete("/api/v1/tips/{tip_id}")
async def api_delete_tip(
tip_id: str, wallet: WalletTypeInfo = Depends(get_key_type)
):
async def api_delete_tip(tip_id: str, wallet: WalletTypeInfo = Depends(get_key_type)):
"""Delete the tip with the given tip_id"""
tip = await get_tip(tip_id)
if not tip:
Expand All @@ -200,8 +196,7 @@ async def api_delete_tip(

@tipjar_ext.delete("/api/v1/tipjars/{tipjar_id}")
async def api_delete_tipjar(
tipjar_id: int,
wallet: WalletTypeInfo = Depends(get_key_type)
tipjar_id: int, wallet: WalletTypeInfo = Depends(get_key_type)
):
"""Delete the tipjar with the given tipjar_id"""
tipjar = await get_tipjar(tipjar_id)
Expand All @@ -210,7 +205,6 @@ async def api_delete_tipjar(
status_code=HTTPStatus.NOT_FOUND, detail="No tipjar with this ID!"
)
if tipjar.wallet != wallet.wallet.id:

raise HTTPException(
status_code=HTTPStatus.FORBIDDEN,
detail="Not authorized to delete this tipjar!",
Expand Down

0 comments on commit 01323f8

Please sign in to comment.