From 5c87c5ad8523260645dc809372cadf1c3b3c703a Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Thu, 16 Jun 2022 13:01:10 -0700 Subject: [PATCH] Add UI elements for swap fee and TXID payout. Fix bugs. --- api/lightning/node.py | 7 +++--- api/logics.py | 10 ++++---- api/views.py | 5 +++- frontend/src/components/BottomBar.js | 1 + .../components/Dialogs/ExchangeSummary.tsx | 22 +++++++++++++++++ frontend/src/components/TradeBox.js | 24 ++++++++++++------- robosats/celery/__init__.py | 2 +- 7 files changed, 50 insertions(+), 21 deletions(-) diff --git a/api/lightning/node.py b/api/lightning/node.py index 96ad7e69..655d5528 100644 --- a/api/lightning/node.py +++ b/api/lightning/node.py @@ -1,6 +1,6 @@ import grpc, os, hashlib, secrets, ring -from robosats.api.models import OnchainPayment + from . import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub from . import invoices_pb2 as invoicesrpc, invoices_pb2_grpc as invoicesstub from . import router_pb2 as routerrpc, router_pb2_grpc as routerstub @@ -118,7 +118,7 @@ class LNNode: def pay_onchain(cls, onchainpayment): """Send onchain transaction for buyer payouts""" - if bool(config("DISABLE_ONCHAIN")): + if config("DISABLE_ONCHAIN", cast=bool): return False request = lnrpc.SendCoinsRequest(addr=onchainpayment.address, @@ -126,13 +126,12 @@ class LNNode: sat_per_vbyte=int(onchainpayment.mining_fee_rate), label=str("Payout order #" + str(onchainpayment.order_paid_TX.id)), spend_unconfirmed=True) + response = cls.lightningstub.SendCoins(request, metadata=[("macaroon", MACAROON.hex())]) - print(response) onchainpayment.txid = response.txid - onchainpayment.status = OnchainPayment.Status.MEMPO onchainpayment.save() return True diff --git a/api/logics.py b/api/logics.py index 6bd29e8b..f7b9a8a9 100644 --- a/api/logics.py +++ b/api/logics.py @@ -516,10 +516,6 @@ class Logics: MAX_SWAP_FEE = float(config('MAX_SWAP_FEE')) SWAP_LAMBDA = float(config('SWAP_LAMBDA')) swap_fee_rate = MIN_SWAP_FEE + (MAX_SWAP_FEE - MIN_SWAP_FEE) * math.exp(-SWAP_LAMBDA * float(balance.onchain_fraction)) - print("MIN_SWAP_FEE",MIN_SWAP_FEE) - print("MAX_SWAP_FEE",MAX_SWAP_FEE) - print("SWAP_LAMBDA",SWAP_LAMBDA) - print("swap_fee_rate",swap_fee_rate) return swap_fee_rate * 100 @@ -589,7 +585,7 @@ class Logics: context["swap_failure_reason"] = "Order amount is too small to be eligible for a swap" return True, context - if not bool(config("DISABLE_ONCHAIN")): + if config("DISABLE_ONCHAIN", cast=bool): context["swap_allowed"] = False context["swap_failure_reason"] = "On-the-fly submarine swaps are dissabled" return True, context @@ -1316,7 +1312,7 @@ class Logics: @classmethod def pay_buyer(cls, order): '''Pays buyer invoice or onchain address''' - + # Pay to buyer invoice if not order.is_swap: ##### Background process "follow_invoices" will try to pay this invoice until success @@ -1331,6 +1327,8 @@ class Logics: else: valid = LNNode.pay_onchain(order.payout_tx) if valid: + order.payout_tx.status = OnchainPayment.Status.MEMPO + order.payout_tx.save() order.status = Order.Status.SUC order.save() send_message.delay(order.id,'trade_successful') diff --git a/api/views.py b/api/views.py index 1365e60e..bc0d6853 100644 --- a/api/views.py +++ b/api/views.py @@ -13,7 +13,7 @@ from django.contrib.auth.models import User from api.serializers import ListOrderSerializer, MakeOrderSerializer, UpdateOrderSerializer, ClaimRewardSerializer, PriceSerializer, UserGenSerializer from api.models import LNPayment, MarketTick, OnchainPayment, Order, Currency, Profile -from control.models import AccountingDay +from control.models import AccountingDay, BalanceLog from api.logics import Logics from api.messages import Telegram from secrets import token_urlsafe @@ -410,6 +410,7 @@ class OrderView(viewsets.ViewSet): data["sent_satoshis"] = order.payout_tx.sent_satoshis if order.payout_tx.status in [OnchainPayment.Status.MEMPO, OnchainPayment.Status.CONFI]: data["txid"] = order.payout_tx.txid + data["network"] = str(config("NETWORK")) @@ -892,6 +893,8 @@ class InfoView(ListAPIView): context["taker_fee"] = float(config("FEE"))*(1 - float(config("MAKER_FEE_SPLIT"))) context["bond_size"] = float(config("DEFAULT_BOND_SIZE")) + context["current_swap_fee_rate"] = Logics.compute_swap_fee_rate(BalanceLog.objects.latest('time')) + if request.user.is_authenticated: context["nickname"] = request.user.username context["referral_code"] = str(request.user.profile.referral_code) diff --git a/frontend/src/components/BottomBar.js b/frontend/src/components/BottomBar.js index e37c5ace..2daef79d 100644 --- a/frontend/src/components/BottomBar.js +++ b/frontend/src/components/BottomBar.js @@ -400,6 +400,7 @@ bottomBarPhone =()=>{ lastDayNonkycBtcPremium={this.state.last_day_nonkyc_btc_premium} makerFee={this.state.maker_fee} takerFee={this.state.taker_fee} + swapFeeRate={this.state.current_swap_fee_rate} /> { const { t } = useTranslation(); + if (swapFeeRate === null || swapFeeRate === undefined) { + swapFeeRate = 0 + } return ( + + + + + + + + + + + diff --git a/frontend/src/components/TradeBox.js b/frontend/src/components/TradeBox.js index 6b6781be..2f31c3ac 100644 --- a/frontend/src/components/TradeBox.js +++ b/frontend/src/components/TradeBox.js @@ -1,6 +1,6 @@ import React, { Component } from "react"; import { withTranslation, Trans} from "react-i18next"; -import { Tabs, Tab, IconButton, Box, Link, Paper, Rating, Button, Tooltip, CircularProgress, Grid, Typography, TextField, List, ListItem, ListItemText, Divider, ListItemIcon, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle} from "@mui/material" +import { Alert, AlertTitle, Tabs, Tab, IconButton, Box, Link, Paper, Rating, Button, Tooltip, CircularProgress, Grid, Typography, TextField, List, ListItem, ListItemText, Divider, ListItemIcon, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle} from "@mui/material" import QRCode from "react-qr-code"; import Countdown, { zeroPad} from 'react-countdown'; import Chat from "./EncryptedChat" @@ -719,7 +719,7 @@ class TradeBox extends Component { - {t("RoboSats will do a swap and send the Sats to your onchain address for a fee.")} + {t("EXPERIMENTAL: ")}{t("RoboSats will do a swap and send the Sats to your onchain address.")} @@ -1248,13 +1248,19 @@ handleRatingRobosatsChange=(e)=>{ {/* SHOW TXID IF USER RECEIVES ONCHAIN */} {this.props.data.txid ? - - - {t("Your TXID:")} - - - {this.props.data.txid} - + + + {t("Your TXID")} + + {navigator.clipboard.writeText(this.props.data.txid)}}> + + + + + + {this.props.data.txid} + + : null} diff --git a/robosats/celery/__init__.py b/robosats/celery/__init__.py index 0e8f5425..1cfdcf48 100644 --- a/robosats/celery/__init__.py +++ b/robosats/celery/__init__.py @@ -57,7 +57,7 @@ app.conf.beat_schedule = { }, "compute-node-balance": { # Logs LND channel and wallet balance "task":"compute_node_balance", - "schedule": timedelta(minutes=15), + "schedule": timedelta(minutes=60), } }