Skip to content

Commit 3da8388

Browse files
committed
swap: fix incorrect multi Loop In warning
1 parent 67de28e commit 3da8388

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

app/src/components/loop/LoopActions.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,24 @@ const LoopActions: React.FC = () => {
5151
const {
5252
setDirection,
5353
inferredDirection,
54-
loopOutAllowed,
55-
loopInAllowed,
54+
isLoopOutMinimumMet,
55+
isLoopInMinimumMet,
56+
hasValidLoopInPeers,
5657
} = buildSwapStore;
5758
const handleLoopOut = useCallback(() => setDirection(SwapDirection.OUT), [
5859
setDirection,
5960
]);
6061
const handleLoopIn = useCallback(() => setDirection(SwapDirection.IN), [setDirection]);
6162
const selectedCount = buildSwapStore.selectedChanIds.length;
6263

64+
let note =
65+
!isLoopOutMinimumMet || !isLoopInMinimumMet
66+
? l('loopMinimumNote', { min: formatSats(buildSwapStore.termsForDirection.min) })
67+
: '';
68+
if (!hasValidLoopInPeers) {
69+
note = l('loopInNote');
70+
}
71+
6372
const { Wrapper, Actions, ActionBar, CloseIcon, Selected, Note } = Styled;
6473
return (
6574
<Wrapper>
@@ -69,31 +78,27 @@ const LoopActions: React.FC = () => {
6978
<CloseIcon onClick={buildSwapStore.cancel} />
7079
<Selected count={selectedCount} />
7180
<Button
72-
primary={loopOutAllowed && inferredDirection === SwapDirection.OUT}
81+
primary={isLoopOutMinimumMet && inferredDirection === SwapDirection.OUT}
7382
borderless
7483
onClick={handleLoopOut}
75-
disabled={!loopOutAllowed}
84+
disabled={!isLoopOutMinimumMet}
7685
>
7786
{l('common.loopOut')}
7887
</Button>
7988
<Button
80-
primary={loopInAllowed && inferredDirection === SwapDirection.IN}
89+
primary={
90+
hasValidLoopInPeers &&
91+
isLoopInMinimumMet &&
92+
inferredDirection === SwapDirection.IN
93+
}
8194
borderless
8295
onClick={handleLoopIn}
83-
disabled={!loopInAllowed}
96+
disabled={!hasValidLoopInPeers || !isLoopInMinimumMet}
8497
>
8598
{l('common.loopIn')}
8699
</Button>
87100
</ActionBar>
88-
{!loopOutAllowed && !loopInAllowed ? (
89-
<Note>
90-
{l('loopMinimumNote', {
91-
min: formatSats(buildSwapStore.termsForDirection.min),
92-
})}
93-
</Note>
94-
) : !loopInAllowed ? (
95-
<Note>{l('loopInNote')}</Note>
96-
) : null}
101+
{note && <Note>{note}</Note>}
97102
</Actions>
98103
) : (
99104
<Button onClick={buildSwapStore.startSwap}>

app/src/store/stores/buildSwapStore.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,24 @@ class BuildSwapStore {
148148
}
149149

150150
/**
151-
* determines if Loop In is allowed. the balance of selected (or all)
152-
* channels must be greater than the minimum swap allowed. if multiple
153-
* channels are selected, they must all be with the same peer
151+
* determines if the selected channels all use the same peer. also
152+
* return true if no channels are selected
154153
*/
155154
@computed
156-
get loopInAllowed() {
155+
get hasValidLoopInPeers() {
156+
if (this.selectedChanIds.length > 0) {
157+
return this.loopInLastHop !== undefined;
158+
}
159+
160+
return true;
161+
}
162+
163+
/**
164+
* determines if the balance of selected (or all) channels are
165+
* greater than the minimum swap allowed
166+
*/
167+
@computed
168+
get isLoopInMinimumMet() {
157169
const { min, max } = this.getTermsForDirection(SwapDirection.IN);
158170
if (!max.gt(min)) return false;
159171

@@ -169,7 +181,7 @@ class BuildSwapStore {
169181
* channels must be greater than the minimum swap allowed
170182
*/
171183
@computed
172-
get loopOutAllowed() {
184+
get isLoopOutMinimumMet() {
173185
const { min, max } = this.getTermsForDirection(SwapDirection.OUT);
174186
if (!max.gt(min)) return false;
175187

0 commit comments

Comments
 (0)