Skip to content

Commit

Permalink
Merge pull request #2741 from shubhamkmr04/shubham/more-swap-updates
Browse files Browse the repository at this point in the history
[swaps] Enhancements
  • Loading branch information
kaloudis authored Jan 16, 2025
2 parents b75c3dd + f5c6070 commit d14c642
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
2 changes: 2 additions & 0 deletions stores/SwapStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ export default class SwapStore {
let stateColor;
switch (status) {
case 'transaction.claimed':
case 'invoice.settled':
stateColor = 'green';
break;
case 'invoice.failedToPay':
case 'swap.expired':
case 'invoice.expired':
case 'transaction.lockupFailed':
stateColor = themeColor('error');
break;
Expand Down
28 changes: 20 additions & 8 deletions views/SwapDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,21 @@ interface SwapDetailsProps {
navigation: StackNavigationProp<any, any>;
route: Route<
'SwapDetails',
{ swapData: any; keys: any; endpoint: any; invoice: any }
{
swapData: any;
keys: any;
endpoint: string;
invoice: string;
fee: string;
}
>;
NodeInfoStore?: NodeInfoStore;
SwapStore?: SwapStore;
}

interface SwapDetailsState {
updates: any;
error: any;
updates: string | null;
error: string | { message?: string } | null;
loading: boolean;
}

Expand Down Expand Up @@ -229,7 +235,7 @@ export default class SwapDetails extends React.Component<
pollingInterval: number,
isSubmarineSwap: boolean
) => {
const { keys, endpoint, swapData } = this.props.route.params;
const { keys, endpoint, swapData, fee } = this.props.route.params;

if (!createdResponse || !createdResponse.id) {
console.error('Invalid response:', createdResponse);
Expand Down Expand Up @@ -295,7 +301,8 @@ export default class SwapDetails extends React.Component<
swapData.lockupAddress,
swapData.destinationAddress,
swapData.preimage,
data.transaction.hex
data.transaction.hex,
fee
);
} else if (
data.status === 'invoice.expired' ||
Expand Down Expand Up @@ -481,7 +488,8 @@ export default class SwapDetails extends React.Component<
lockupAddress: string,
destinationAddress: string,
preimage: any,
transactionHex: string
transactionHex: string,
fee: string
) => {
try {
const dObject = keys.__D;
Expand All @@ -508,7 +516,7 @@ export default class SwapDetails extends React.Component<
transactionHex,
lockupAddress,
destinationAddress,
feeRate: 2, // TODO
feeRate: Number(fee),
isTestnet: this.props.NodeInfoStore!.nodeInfo.isTestNet
});

Expand Down Expand Up @@ -581,7 +589,11 @@ export default class SwapDetails extends React.Component<
{this.state.loading && <LoadingIndicator />}
{error && (
<ErrorMessage
message={error?.message || String(error)}
message={
typeof error === 'object' && 'message' in error
? error?.message
: String(error)
}
/>
)}
{updates && (
Expand Down
31 changes: 25 additions & 6 deletions views/Swaps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
ErrorMessage,
SuccessMessage
} from '../components/SuccessErrorMessage';
import OnchainFeeInput from '../components/OnchainFeeInput';

import { localeString } from '../utils/LocaleUtils';
import { themeColor } from '../utils/ThemeUtils';
Expand Down Expand Up @@ -58,6 +59,7 @@ interface SwapPaneState {
apiUpdates: any;
response: any;
fetchingInvoice: boolean;
fee: string;
}

@inject('SwapStore', 'UnitsStore', 'InvoicesStore')
Expand All @@ -76,7 +78,8 @@ export default class SwapPane extends React.PureComponent<
apiUpdates: '',
apiError: null,
response: null,
fetchingInvoice: false
fetchingInvoice: false,
fee: ''
};

async UNSAFE_componentWillMount() {
Expand All @@ -94,7 +97,8 @@ export default class SwapPane extends React.PureComponent<
apiUpdates,
invoice,
isValid,
fetchingInvoice
fetchingInvoice,
fee
} = this.state;
const { subInfo, reverseInfo, loading } = SwapStore;
const info: any = reverse ? reverseInfo : subInfo;
Expand Down Expand Up @@ -267,7 +271,8 @@ export default class SwapPane extends React.PureComponent<
swapData: responseData,
keys,
endpoint: HOST,
invoice: destinationAddress
invoice: destinationAddress,
fee
});
});
} catch (error: any) {
Expand Down Expand Up @@ -904,6 +909,23 @@ export default class SwapPane extends React.PureComponent<
disabled={errorMsg}
/>
</View>
<View style={{ paddingHorizontal: 20 }}>
<Text
style={{
color: themeColor('secondaryText'),
marginTop: 10
}}
>
{localeString('views.Send.feeSatsVbyte')}
</Text>
<OnchainFeeInput
fee={fee}
onChangeFee={(text: string) =>
this.setState({ fee: text })
}
navigation={navigation}
/>
</View>

<View>
<Button
Expand All @@ -914,9 +936,6 @@ export default class SwapPane extends React.PureComponent<
? createReverseSwap(invoice)
: createSubmarineSwap(invoice);
}}
containerStyle={{
marginTop: 10
}}
disabled={!isValid}
/>
</View>
Expand Down

0 comments on commit d14c642

Please sign in to comment.