Skip to content

Commit

Permalink
USD input
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Oct 8, 2023
1 parent 76307bb commit 6721951
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cashu/lightning/strike.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def get_invoice_quote(self, bolt11: str) -> PaymentQuote:
r.raise_for_status()
except Exception:
error_message = r.json()["data"]["message"]
return PaymentResponse(None, None, None, None, error_message)
raise Exception(error_message)
data = r.json()

amount_cent = int(float(data.get("amount").get("amount")) * 100)
Expand Down
2 changes: 2 additions & 0 deletions cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ async def getmelt(self, bolt11: str) -> PaymentQuote:
int: Amount to pay
"""
quote = await self.lightning.get_invoice_quote(bolt11)
if "error_message" in quote:
raise LightningError(quote["error_message"])
invoice = Invoice(
amount=quote.amount,
hash=quote.id,
Expand Down
16 changes: 9 additions & 7 deletions cashu/wallet/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async def pay(ctx: Context, invoice: str, yes: bool):


@cli.command("invoice", help="Create Lighting invoice.")
@click.argument("amount", type=int)
@click.argument("amount", type=float)
@click.option("--hash", default="", help="Hash of the paid invoice.", type=str)
@click.option(
"--split",
Expand All @@ -194,7 +194,9 @@ async def pay(ctx: Context, invoice: str, yes: bool):
)
@click.pass_context
@coro
async def invoice(ctx: Context, amount: int, hash: str, split: int):
async def invoice(ctx: Context, amount: float, hash: str, split: int):
# USD to cent
amount = int(amount * 100)
wallet: Wallet = ctx.obj["WALLET"]
await wallet.load_mint()
wallet.status()
Expand All @@ -213,13 +215,13 @@ async def invoice(ctx: Context, amount: int, hash: str, split: int):
elif amount and not hash:
invoice = await wallet.request_mint(amount)
if invoice.pr:
print(f"Pay invoice to mint {amount} sat:")
print(f"Pay invoice to mint {invoice.amount/100:.2f} USD:")
print("")
print(f"Invoice: {invoice.pr}")
print("")
print(
"If you abort this you can use this command to recheck the"
f" invoice:\ncashu invoice {amount} --hash {invoice.hash}"
f" invoice:\ncashu invoice {amount/100:.2f} --hash {invoice.hash}"
)
check_until = time.time() + 5 * 60 # check for five minutes
print("")
Expand Down Expand Up @@ -329,12 +331,12 @@ async def balance(ctx: Context, verbose):

if verbose:
print(
f"Balance: {wallet.available_balance} cent (pending:"
f" {wallet.balance-wallet.available_balance} cent) in"
f"Balance: {wallet.available_balance/100:.2f} USD (pending:"
f" {(wallet.balance-wallet.available_balance)/100:.2f} cent) in"
f" {len([p for p in wallet.proofs if not p.reserved])} tokens"
)
else:
print(f"Balance: {wallet.available_balance} cent")
print(f"Balance: {wallet.available_balance/100:.2f} USD")


@cli.command("send", help="Send tokens.")
Expand Down
2 changes: 1 addition & 1 deletion cashu/wallet/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ def proof_amounts(self):
return [p.amount for p in sorted(self.proofs, key=lambda p: p.amount)]

def status(self):
print(f"Balance: {self.available_balance} cents")
print(f"Balance: {self.available_balance/100:.2f} USD")

def balance_per_keyset(self):
return {
Expand Down

0 comments on commit 6721951

Please sign in to comment.