@@ -56,7 +56,8 @@ export class SwapModalComponent implements OnInit, AfterViewInit, OnDestroy {
56
56
this . inputFormGroup = this . formBuilder . group ( {
57
57
amount : [ this . serviceInfo . limits ?. minimal , [ Validators . required , Validators . min ( this . serviceInfo . limits ?. minimal || 0 ) , Validators . max ( this . serviceInfo . limits ?. maximal || 0 ) ] ] ,
58
58
acceptZeroConf : [ false ] ,
59
- sendFromInternal : [ true ]
59
+ sendFromInternal : [ true ] ,
60
+ refundAddress : [ { value : '' , disabled : true } ]
60
61
} ) ;
61
62
this . addressFormGroup = this . formBuilder . group ( {
62
63
addressType : [ 'local' , [ Validators . required ] ] ,
@@ -89,6 +90,25 @@ export class SwapModalComponent implements OnInit, AfterViewInit, OnDestroy {
89
90
this . addressFormGroup . setErrors ( { Invalid : true } ) ;
90
91
} ) ;
91
92
}
93
+ if ( this . direction === SwapTypeEnum . SWAP_IN ) {
94
+ this . inputFormGroup . controls . sendFromInternal . valueChanges .
95
+ pipe ( takeUntil ( this . unSubs [ 4 ] ) ) .
96
+ subscribe ( ( ) => {
97
+ this . onSendFromInternalChange ( ) ;
98
+ } ) ;
99
+ }
100
+ }
101
+
102
+ onSendFromInternalChange ( ) {
103
+ if ( ! this . inputFormGroup . controls . sendFromInternal . value ) {
104
+ this . inputFormGroup . controls . refundAddress . enable ( ) ;
105
+ this . inputFormGroup . controls . refundAddress . setValidators ( [ Validators . required ] ) ;
106
+ this . inputFormGroup . controls . refundAddress . updateValueAndValidity ( ) ;
107
+ } else {
108
+ this . inputFormGroup . controls . refundAddress . disable ( ) ;
109
+ this . inputFormGroup . controls . refundAddress . clearValidators ( ) ;
110
+ this . inputFormGroup . controls . refundAddress . updateValueAndValidity ( ) ;
111
+ }
92
112
}
93
113
94
114
onAddressTypeChange ( event : any ) {
@@ -115,7 +135,22 @@ export class SwapModalComponent implements OnInit, AfterViewInit, OnDestroy {
115
135
this . stepper . selected ?. stepControl . setErrors ( null ) ;
116
136
this . stepper . next ( ) ;
117
137
if ( this . direction === SwapTypeEnum . SWAP_IN ) {
118
- this . boltzService . swapIn ( this . inputFormGroup . controls . amount . value , this . isSendFromInternalCompatible ? this . inputFormGroup . controls . sendFromInternal . value : null ) . pipe ( takeUntil ( this . unSubs [ 2 ] ) ) .
138
+ const refundAddress = this . inputFormGroup . controls . sendFromInternal . value ?
139
+ null : this . inputFormGroup . controls . refundAddress . value ;
140
+
141
+ const sendFromInternal = this . isSendFromInternalCompatible ? this . inputFormGroup . controls . sendFromInternal . value : null ;
142
+
143
+ if ( ! sendFromInternal && ! refundAddress ) {
144
+ this . stepper . selected ?. stepControl . setErrors ( { Invalid : true } ) ;
145
+ this . flgEditable = true ;
146
+ return ;
147
+ }
148
+
149
+ this . boltzService . swapIn (
150
+ this . inputFormGroup . controls . amount . value ,
151
+ sendFromInternal ,
152
+ refundAddress
153
+ ) . pipe ( takeUntil ( this . unSubs [ 2 ] ) ) .
119
154
subscribe ( {
120
155
next : ( swapStatus : CreateSwapResponse ) => {
121
156
this . swapStatus = swapStatus ;
@@ -156,7 +191,11 @@ export class SwapModalComponent implements OnInit, AfterViewInit, OnDestroy {
156
191
case 1 :
157
192
if ( this . inputFormGroup . controls . amount . value ) {
158
193
if ( this . direction === SwapTypeEnum . SWAP_IN ) {
159
- this . inputFormLabel = this . swapDirectionCaption + ' Amount: ' + ( this . decimalPipe . transform ( this . inputFormGroup . controls . amount . value ? this . inputFormGroup . controls . amount . value : 0 ) ) + ' Sats | Send from Internal Wallet: ' + ( this . inputFormGroup . controls . sendFromInternal . value ? 'Yes' : 'No' ) ;
194
+ let summary = this . swapDirectionCaption + ' Amount: ' + ( this . decimalPipe . transform ( this . inputFormGroup . controls . amount . value ? this . inputFormGroup . controls . amount . value : 0 ) ) + ' Sats | Send from Internal Wallet: ' + ( this . inputFormGroup . controls . sendFromInternal . value ? 'Yes' : 'No' ) ;
195
+ if ( ! this . inputFormGroup . controls . sendFromInternal . value && this . inputFormGroup . controls . refundAddress . value ) {
196
+ summary += ' | Refund Address: ' + this . inputFormGroup . controls . refundAddress . value ;
197
+ }
198
+ this . inputFormLabel = summary ;
160
199
} else {
161
200
this . inputFormLabel = this . swapDirectionCaption + ' Amount: ' + ( this . decimalPipe . transform ( this . inputFormGroup . controls . amount . value ? this . inputFormGroup . controls . amount . value : 0 ) ) + ' Sats | Zero Conf: ' + ( this . inputFormGroup . controls . acceptZeroConf . value ? 'Yes' : 'No' ) ;
162
201
}
@@ -201,7 +240,12 @@ export class SwapModalComponent implements OnInit, AfterViewInit, OnDestroy {
201
240
onRestart ( ) {
202
241
this . stepper . reset ( ) ;
203
242
this . flgEditable = true ;
204
- this . inputFormGroup . reset ( { amount : this . serviceInfo . limits ?. minimal , acceptZeroConf : false , sendFromInternal : true } ) ;
243
+ this . inputFormGroup . reset ( {
244
+ amount : this . serviceInfo . limits ?. minimal ,
245
+ acceptZeroConf : false ,
246
+ sendFromInternal : true ,
247
+ refundAddress : ''
248
+ } ) ;
205
249
this . statusFormGroup . reset ( ) ;
206
250
this . addressFormGroup . reset ( { addressType : 'local' , address : '' } ) ;
207
251
this . addressFormGroup . controls . address . disable ( ) ;
0 commit comments