Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lndmobile/LndMobile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export interface ILndMobile {
privateKey: string,
servicePubKey: string,
feeRate: number,
minerFee: number,
timeoutBlockHeight: number,
destinationAddress: string,
lockupAddress: string,
Expand Down
2 changes: 2 additions & 0 deletions lndmobile/LndMobileInjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ export interface ILndMobileInjections {
privateKey,
servicePubKey,
feeRate,
minerFee,
timeoutBlockHeight,
destinationAddress,
lockupAddress,
Expand All @@ -597,6 +598,7 @@ export interface ILndMobileInjections {
privateKey: string;
servicePubKey: string;
feeRate: number;
minerFee: number;
timeoutBlockHeight: number;
destinationAddress: string;
lockupAddress: string;
Expand Down
3 changes: 3 additions & 0 deletions lndmobile/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const createRefundTransaction = async ({
privateKey,
servicePubKey,
feeRate,
minerFee,
timeoutBlockHeight,
destinationAddress,
lockupAddress,
Expand All @@ -142,6 +143,7 @@ export const createRefundTransaction = async ({
privateKey: string;
servicePubKey: string;
feeRate: number;
minerFee: number;
timeoutBlockHeight: number;
destinationAddress: string;
lockupAddress: string;
Expand All @@ -158,6 +160,7 @@ export const createRefundTransaction = async ({
privateKey,
servicePubKey,
feeRate,
minerFee,
timeoutBlockHeight,
destinationAddress,
lockupAddress,
Expand Down
2 changes: 2 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2356,6 +2356,8 @@
"views.Swaps.uncooperative": "Uncooperative refund",
"views.Swaps.infoText": "It is recommended you only attempt an uncooperative refund if the service provider is not operational.",
"views.Swaps.initiateRefund": "Initiate Refund",
"views.Swaps.feeRate": "Fee Rate",
"views.Swaps.minerFee": "Miner Fee",
"views.Swaps.networkFee": "Network fee",
"views.Swaps.serviceFee": "Service fee",
"views.Swaps.missingAmount": "Please enter an amount",
Expand Down
139 changes: 118 additions & 21 deletions views/Swaps/Refund.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Route } from '@react-navigation/native';
import lndMobile from '../../lndmobile/LndMobileInjection';
const { createRefundTransaction } = lndMobile.swaps;

import { ButtonGroup } from '@rneui/themed';

import Button from '../../components/Button';

import Header from '../../components/Header';
Expand All @@ -15,6 +17,7 @@ import OnchainFeeInput from '../../components/OnchainFeeInput';
import Screen from '../../components/Screen';
import Switch from '../../components/Switch';
import Text from '../../components/Text';
import TextInput from '../../components/TextInput';
import AddressInput from '../../components/AddressInput';
import {
ErrorMessage,
Expand All @@ -25,6 +28,10 @@ import { Row } from '../../components/layout/Row';
import BackendUtils from '../../utils/BackendUtils';
import { localeString, pascalToHumanReadable } from '../../utils/LocaleUtils';
import { themeColor } from '../../utils/ThemeUtils';
import {
buttonTextStyle,
getButtonGroupStyles
} from '../../utils/buttonGroupStyles';

import SwapStore from '../../stores/SwapStore';
import NodeInfoStore from '../../stores/NodeInfoStore';
Expand All @@ -51,7 +58,9 @@ interface RefundSwapProps {

interface RefundSwapState {
destinationAddress: string;
fee: string;
feeRate: string;
minerFee: string;
selectedFeeIndex: number;
error: string;
swapData: Swap;
loading: boolean;
Expand All @@ -69,7 +78,9 @@ export default class RefundSwap extends React.Component<
> {
state = {
destinationAddress: '',
fee: '',
feeRate: '',
minerFee: '',
selectedFeeIndex: 0,
error: '',
loading: false,
swapData: this.props.route.params.swapData,
Expand All @@ -81,11 +92,13 @@ export default class RefundSwap extends React.Component<

createRefundTransaction = async (
swapData: Swap,
fee: any,
feeRate: string,
minerFee: string,
destinationAddress: string
): Promise<void> => {
const { SwapStore } = this.props;
const { uncooperative } = this.state;
const { uncooperative, selectedFeeIndex } = this.state;
const isMinerFeeMode = selectedFeeIndex === 1;

try {
const txid = await createRefundTransaction({
Expand All @@ -96,7 +109,8 @@ export default class RefundSwap extends React.Component<
transactionHex: swapData.lockupTransaction?.hex,
privateKey: swapData.refundPrivateKey!,
servicePubKey: swapData.servicePubKey!,
feeRate: Number(fee),
feeRate: !isMinerFeeMode ? Number(feeRate) : 0,
minerFee: isMinerFeeMode ? Number(minerFee) : 0,
timeoutBlockHeight: Number(swapData.timeoutBlockHeight),
destinationAddress,
lockupAddress: swapData.effectiveLockupAddress!,
Expand Down Expand Up @@ -140,7 +154,9 @@ export default class RefundSwap extends React.Component<
render() {
const { navigation, SwapStore, InvoicesStore } = this.props;
const {
fee,
feeRate,
minerFee,
selectedFeeIndex,
destinationAddress,
swapData,
error,
Expand All @@ -151,6 +167,9 @@ export default class RefundSwap extends React.Component<
rawToggle
} = this.state;

const isValidMinerFee =
Number(minerFee) > 0 && Number.isInteger(Number(minerFee));

const rawDetails = {
endpoint: swapData.endpoint.replace('/v2', ''),
swapId: swapData.id,
Expand All @@ -159,7 +178,8 @@ export default class RefundSwap extends React.Component<
transactionHex: swapData.lockupTransaction?.hex,
privateKey: swapData.refundPrivateKey,
servicePubKey: swapData.servicePubKey,
feeRate: Number(fee),
feeRate: selectedFeeIndex === 0 ? Number(feeRate) : 0,
minerFee: selectedFeeIndex === 1 ? Number(minerFee) : 0,
timeoutBlockHeight: Number(swapData.timeoutBlockHeight),
destinationAddress,
lockupAddress: swapData.effectiveLockupAddress,
Expand Down Expand Up @@ -282,21 +302,96 @@ export default class RefundSwap extends React.Component<
/>
)}
</View>
<Text
style={{
color: themeColor('secondaryText'),
marginTop: 10
<ButtonGroup
onPress={(index: number) =>
this.setState({
selectedFeeIndex: index,
error: ''
})
}
selectedIndex={selectedFeeIndex}
buttons={[
{
element: () => (
<Text
style={{
...buttonTextStyle,
color:
selectedFeeIndex === 0
? themeColor('background')
: themeColor('text')
}}
>
{localeString('views.Swaps.feeRate')}
</Text>
)
},
{
element: () => (
<Text
style={{
...buttonTextStyle,
color:
selectedFeeIndex === 1
? themeColor('background')
: themeColor('text')
}}
>
{localeString('views.Swaps.minerFee')}
</Text>
)
}
]}
selectedButtonStyle={
getButtonGroupStyles().selectedButtonStyle
}
containerStyle={{
...getButtonGroupStyles().containerStyle,
marginTop: 14
}}
>
{localeString('views.Send.feeSatsVbyte')}
</Text>
<OnchainFeeInput
fee={fee}
onChangeFee={(text: string) =>
this.setState({ fee: text, error: '' })
innerBorderStyle={
getButtonGroupStyles().innerBorderStyle
}
navigation={navigation}
/>
{selectedFeeIndex === 0 ? (
<>
<Text
style={{
color: themeColor('secondaryText')
}}
>
{localeString('views.Send.feeSatsVbyte')}
</Text>
<OnchainFeeInput
fee={feeRate}
onChangeFee={(text: string) =>
this.setState({ feeRate: text, error: '' })
}
navigation={navigation}
/>
</>
) : (
<>
<Text
style={{
color: themeColor('secondaryText')
}}
>
{`${localeString(
'views.Swaps.minerFee'
)} (${localeString('general.sats')})`}
Comment thread
shubhamkmr04 marked this conversation as resolved.
</Text>
<TextInput
value={minerFee}
onChangeText={(text: string) =>
this.setState({ minerFee: text, error: '' })
}
keyboardType="numeric"
placeholder="0"
error={!!minerFee && !isValidMinerFee}
/>
Comment thread
shubhamkmr04 marked this conversation as resolved.
</>
)}
<Row>
<Text
style={{
Expand Down Expand Up @@ -395,7 +490,8 @@ export default class RefundSwap extends React.Component<
try {
await this.createRefundTransaction(
swapData,
fee,
feeRate,
minerFee,
destinationAddress
);

Expand All @@ -413,7 +509,8 @@ export default class RefundSwap extends React.Component<
disabled={
!destinationAddress ||
this.state.loading ||
fetchingAddress
fetchingAddress ||
(selectedFeeIndex === 1 && !isValidMinerFee)
}
/>
</View>
Expand Down
Loading