Add UI elements for swap fee and TXID payout. Fix bugs.

This commit is contained in:
Reckless_Satoshi 2022-06-16 13:01:10 -07:00
parent efed6b3c0a
commit 5c87c5ad85
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
7 changed files with 50 additions and 21 deletions

View File

@ -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

View File

@ -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')

View File

@ -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)

View File

@ -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}
/>
<ProfileDialog

View File

@ -19,6 +19,7 @@ import SmartToyIcon from '@mui/icons-material/SmartToy';
import PercentIcon from '@mui/icons-material/Percent';
import PriceChangeIcon from '@mui/icons-material/PriceChange';
import BookIcon from '@mui/icons-material/Book';
import LinkIcon from '@mui/icons-material/Link';
import { pn } from "../../utils/prettyNumbers";
@ -32,6 +33,7 @@ type Props = {
lastDayNonkycBtcPremium: number;
makerFee: number;
takerFee: number;
swapFeeRate: number;
}
const ExchangeSummaryDialog = ({
@ -44,8 +46,12 @@ const ExchangeSummaryDialog = ({
lastDayNonkycBtcPremium,
makerFee,
takerFee,
swapFeeRate,
}: Props): JSX.Element => {
const { t } = useTranslation();
if (swapFeeRate === null || swapFeeRate === undefined) {
swapFeeRate = 0
}
return (
<Dialog
@ -160,6 +166,22 @@ const ExchangeSummaryDialog = ({
</Grid>
</Grid>
</ListItem>
<Divider />
<ListItem >
<ListItemIcon>
<LinkIcon />
</ListItemIcon>
<ListItemText
primaryTypographyProps={{fontSize: '14px'}}
secondaryTypographyProps={{fontSize: '12px'}}
primary={`${swapFeeRate.toPrecision(3)}%`}
secondary={t("Current onchain payout fee")}
/>
</ListItem>
</List>
</DialogContent>
</Dialog>

View File

@ -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 {
<List dense={true}>
<ListItem>
<Typography variant="body2">
{t("RoboSats will do a swap and send the Sats to your onchain address for a fee.")}
<b>{t("EXPERIMENTAL: ")}</b>{t("RoboSats will do a swap and send the Sats to your onchain address.")}
</Typography>
</ListItem>
@ -1248,13 +1248,19 @@ handleRatingRobosatsChange=(e)=>{
{/* SHOW TXID IF USER RECEIVES ONCHAIN */}
{this.props.data.txid ?
<Grid item xs={12} align="center">
<Typography variant="body2" align="center">
<b>{t("Your TXID:")}</b>
</Typography>
<Typography variant="body2" align="center">
<Link target='_blank' href={"http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/tx/"+this.props.data.txid}>{this.props.data.txid}</Link>
</Typography>
<Grid item xs={12} align="left">
<Alert severity="success">
<AlertTitle>{t("Your TXID")}
<Tooltip disableHoverListener enterTouchDelay={0} title={t("Copied!")}>
<IconButton color="inherit" onClick={() => {navigator.clipboard.writeText(this.props.data.txid)}}>
<ContentCopy sx={{width:16,height:16}}/>
</IconButton>
</Tooltip>
</AlertTitle>
<Typography variant="body2" align="center" sx={{ wordWrap: "break-word", width:220}}>
<Link target='_blank' href={"http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/"+(this.props.data.network =="testnet"? "testnet/": "")+"tx/"+this.props.data.txid}>{this.props.data.txid}</Link>
</Typography>
</Alert>
</Grid>
: null}

View File

@ -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),
}
}