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 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 lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
from . import invoices_pb2 as invoicesrpc, invoices_pb2_grpc as invoicesstub from . import invoices_pb2 as invoicesrpc, invoices_pb2_grpc as invoicesstub
from . import router_pb2 as routerrpc, router_pb2_grpc as routerstub from . import router_pb2 as routerrpc, router_pb2_grpc as routerstub
@ -118,7 +118,7 @@ class LNNode:
def pay_onchain(cls, onchainpayment): def pay_onchain(cls, onchainpayment):
"""Send onchain transaction for buyer payouts""" """Send onchain transaction for buyer payouts"""
if bool(config("DISABLE_ONCHAIN")): if config("DISABLE_ONCHAIN", cast=bool):
return False return False
request = lnrpc.SendCoinsRequest(addr=onchainpayment.address, request = lnrpc.SendCoinsRequest(addr=onchainpayment.address,
@ -126,13 +126,12 @@ class LNNode:
sat_per_vbyte=int(onchainpayment.mining_fee_rate), sat_per_vbyte=int(onchainpayment.mining_fee_rate),
label=str("Payout order #" + str(onchainpayment.order_paid_TX.id)), label=str("Payout order #" + str(onchainpayment.order_paid_TX.id)),
spend_unconfirmed=True) spend_unconfirmed=True)
response = cls.lightningstub.SendCoins(request, response = cls.lightningstub.SendCoins(request,
metadata=[("macaroon", metadata=[("macaroon",
MACAROON.hex())]) MACAROON.hex())])
print(response)
onchainpayment.txid = response.txid onchainpayment.txid = response.txid
onchainpayment.status = OnchainPayment.Status.MEMPO
onchainpayment.save() onchainpayment.save()
return True return True

View File

@ -516,10 +516,6 @@ class Logics:
MAX_SWAP_FEE = float(config('MAX_SWAP_FEE')) MAX_SWAP_FEE = float(config('MAX_SWAP_FEE'))
SWAP_LAMBDA = float(config('SWAP_LAMBDA')) 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)) 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 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" context["swap_failure_reason"] = "Order amount is too small to be eligible for a swap"
return True, context return True, context
if not bool(config("DISABLE_ONCHAIN")): if config("DISABLE_ONCHAIN", cast=bool):
context["swap_allowed"] = False context["swap_allowed"] = False
context["swap_failure_reason"] = "On-the-fly submarine swaps are dissabled" context["swap_failure_reason"] = "On-the-fly submarine swaps are dissabled"
return True, context return True, context
@ -1331,6 +1327,8 @@ class Logics:
else: else:
valid = LNNode.pay_onchain(order.payout_tx) valid = LNNode.pay_onchain(order.payout_tx)
if valid: if valid:
order.payout_tx.status = OnchainPayment.Status.MEMPO
order.payout_tx.save()
order.status = Order.Status.SUC order.status = Order.Status.SUC
order.save() order.save()
send_message.delay(order.id,'trade_successful') 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.serializers import ListOrderSerializer, MakeOrderSerializer, UpdateOrderSerializer, ClaimRewardSerializer, PriceSerializer, UserGenSerializer
from api.models import LNPayment, MarketTick, OnchainPayment, Order, Currency, Profile 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.logics import Logics
from api.messages import Telegram from api.messages import Telegram
from secrets import token_urlsafe from secrets import token_urlsafe
@ -410,6 +410,7 @@ class OrderView(viewsets.ViewSet):
data["sent_satoshis"] = order.payout_tx.sent_satoshis data["sent_satoshis"] = order.payout_tx.sent_satoshis
if order.payout_tx.status in [OnchainPayment.Status.MEMPO, OnchainPayment.Status.CONFI]: if order.payout_tx.status in [OnchainPayment.Status.MEMPO, OnchainPayment.Status.CONFI]:
data["txid"] = order.payout_tx.txid 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["taker_fee"] = float(config("FEE"))*(1 - float(config("MAKER_FEE_SPLIT")))
context["bond_size"] = float(config("DEFAULT_BOND_SIZE")) 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: if request.user.is_authenticated:
context["nickname"] = request.user.username context["nickname"] = request.user.username
context["referral_code"] = str(request.user.profile.referral_code) context["referral_code"] = str(request.user.profile.referral_code)

View File

@ -400,6 +400,7 @@ bottomBarPhone =()=>{
lastDayNonkycBtcPremium={this.state.last_day_nonkyc_btc_premium} lastDayNonkycBtcPremium={this.state.last_day_nonkyc_btc_premium}
makerFee={this.state.maker_fee} makerFee={this.state.maker_fee}
takerFee={this.state.taker_fee} takerFee={this.state.taker_fee}
swapFeeRate={this.state.current_swap_fee_rate}
/> />
<ProfileDialog <ProfileDialog

View File

@ -19,6 +19,7 @@ import SmartToyIcon from '@mui/icons-material/SmartToy';
import PercentIcon from '@mui/icons-material/Percent'; import PercentIcon from '@mui/icons-material/Percent';
import PriceChangeIcon from '@mui/icons-material/PriceChange'; import PriceChangeIcon from '@mui/icons-material/PriceChange';
import BookIcon from '@mui/icons-material/Book'; import BookIcon from '@mui/icons-material/Book';
import LinkIcon from '@mui/icons-material/Link';
import { pn } from "../../utils/prettyNumbers"; import { pn } from "../../utils/prettyNumbers";
@ -32,6 +33,7 @@ type Props = {
lastDayNonkycBtcPremium: number; lastDayNonkycBtcPremium: number;
makerFee: number; makerFee: number;
takerFee: number; takerFee: number;
swapFeeRate: number;
} }
const ExchangeSummaryDialog = ({ const ExchangeSummaryDialog = ({
@ -44,8 +46,12 @@ const ExchangeSummaryDialog = ({
lastDayNonkycBtcPremium, lastDayNonkycBtcPremium,
makerFee, makerFee,
takerFee, takerFee,
swapFeeRate,
}: Props): JSX.Element => { }: Props): JSX.Element => {
const { t } = useTranslation(); const { t } = useTranslation();
if (swapFeeRate === null || swapFeeRate === undefined) {
swapFeeRate = 0
}
return ( return (
<Dialog <Dialog
@ -160,6 +166,22 @@ const ExchangeSummaryDialog = ({
</Grid> </Grid>
</Grid> </Grid>
</ListItem> </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> </List>
</DialogContent> </DialogContent>
</Dialog> </Dialog>

View File

@ -1,6 +1,6 @@
import React, { Component } from "react"; import React, { Component } from "react";
import { withTranslation, Trans} from "react-i18next"; 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 QRCode from "react-qr-code";
import Countdown, { zeroPad} from 'react-countdown'; import Countdown, { zeroPad} from 'react-countdown';
import Chat from "./EncryptedChat" import Chat from "./EncryptedChat"
@ -719,7 +719,7 @@ class TradeBox extends Component {
<List dense={true}> <List dense={true}>
<ListItem> <ListItem>
<Typography variant="body2"> <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> </Typography>
</ListItem> </ListItem>
@ -1248,13 +1248,19 @@ handleRatingRobosatsChange=(e)=>{
{/* SHOW TXID IF USER RECEIVES ONCHAIN */} {/* SHOW TXID IF USER RECEIVES ONCHAIN */}
{this.props.data.txid ? {this.props.data.txid ?
<Grid item xs={12} align="center"> <Grid item xs={12} align="left">
<Typography variant="body2" align="center"> <Alert severity="success">
<b>{t("Your TXID:")}</b> <AlertTitle>{t("Your TXID")}
</Typography> <Tooltip disableHoverListener enterTouchDelay={0} title={t("Copied!")}>
<Typography variant="body2" align="center"> <IconButton color="inherit" onClick={() => {navigator.clipboard.writeText(this.props.data.txid)}}>
<Link target='_blank' href={"http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/tx/"+this.props.data.txid}>{this.props.data.txid}</Link> <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> </Typography>
</Alert>
</Grid> </Grid>
: null} : null}

View File

@ -57,7 +57,7 @@ app.conf.beat_schedule = {
}, },
"compute-node-balance": { # Logs LND channel and wallet balance "compute-node-balance": { # Logs LND channel and wallet balance
"task":"compute_node_balance", "task":"compute_node_balance",
"schedule": timedelta(minutes=15), "schedule": timedelta(minutes=60),
} }
} }