@@ -101,6 +101,7 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
101
101
case SwapAsset .USDC_MATIC :
102
102
redeemAddress = this .request .redeem .request .from ;
103
103
break ;
104
+ case SwapAsset .CRC :
104
105
case SwapAsset .EUR :
105
106
// Assemble recipient object
106
107
redeemAddress = {
@@ -127,7 +128,7 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
127
128
128
129
confirmedSwap = await confirmSwap ({
129
130
id: this .request .swapId ,
130
- } as PreSwap , this .request .redeem .type === SwapAsset .EUR ? {
131
+ } as PreSwap , this .request .redeem .type === SwapAsset .EUR || this . request . redeem . type === SwapAsset . CRC ? {
131
132
asset: this .request .redeem .type ,
132
133
... (redeemAddress as { kty: string , crv: string , x: string }),
133
134
} : {
@@ -276,6 +277,18 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
276
277
// TODO: Validate correct recipient public key
277
278
}
278
279
280
+ if (confirmedSwap .from .asset === SwapAsset .CRC || confirmedSwap .to .asset === SwapAsset .CRC ) {
281
+ // TODO: Fetch contract from OASIS API and compare instead of trusting Fastspot
282
+
283
+ if (hashRoot && confirmedSwap .hash !== hashRoot ) {
284
+ this .$rpc .reject (new Error (' HTLC hash roots do not match' ));
285
+ return ;
286
+ }
287
+ hashRoot = confirmedSwap .hash ;
288
+
289
+ // TODO: Validate correct recipient public key
290
+ }
291
+
279
292
if (! hashRoot ) {
280
293
this .$rpc .reject (new Error (' UNEXPECTED: Could not extract swap hash from contracts' ));
281
294
return ;
@@ -330,6 +343,18 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
330
343
};
331
344
}
332
345
346
+ if (this .request .fund .type === SwapAsset .CRC ) {
347
+ const crcContract = confirmedSwap .contracts [SwapAsset .CRC ] as Contract <SwapAsset .CRC >;
348
+ const crcHtlcData = crcContract .htlc ;
349
+
350
+ fundingHtlcInfo = {
351
+ type: SwapAsset .CRC ,
352
+ hash: hashRoot ,
353
+ timeout: crcContract .timeout ,
354
+ htlcId: crcHtlcData .address ,
355
+ };
356
+ }
357
+
333
358
if (this .request .redeem .type === SwapAsset .NIM ) {
334
359
const nimHtlcData = confirmedSwap .contracts [SwapAsset .NIM ]! .htlc as NimHtlcDetails ;
335
360
@@ -433,6 +458,18 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
433
458
};
434
459
}
435
460
461
+ if (this .request .redeem .type === SwapAsset .CRC ) {
462
+ const crcContract = confirmedSwap .contracts [SwapAsset .CRC ] as Contract <SwapAsset .CRC >;
463
+ const crcHtlcData = crcContract .htlc ;
464
+
465
+ redeemingHtlcInfo = {
466
+ type: SwapAsset .CRC ,
467
+ hash: hashRoot ,
468
+ timeout: crcContract .timeout ,
469
+ htlcId: crcHtlcData .address ,
470
+ };
471
+ }
472
+
436
473
if (this ._isDestroyed ) return ;
437
474
438
475
if (! fundingHtlcInfo || ! redeemingHtlcInfo ) {
@@ -448,6 +485,7 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
448
485
let polygonTransaction: SignedPolygonTransaction | undefined ;
449
486
let refundTransaction: string | undefined ;
450
487
let euroSettlement: string | undefined ;
488
+ let crcSettlement: string | undefined ;
451
489
try {
452
490
const signingResult = await this ._signSwapTransactions ({
453
491
fund: fundingHtlcInfo ,
@@ -459,6 +497,7 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
459
497
nimProxy: nimiqProxyTransaction ,
460
498
btc: bitcoinTransaction ,
461
499
eur: euroSettlement ,
500
+ crc: crcSettlement ,
462
501
usdc: polygonTransaction ,
463
502
refundTx: refundTransaction ,
464
503
} = signingResult );
@@ -505,6 +544,7 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
505
544
btc: bitcoinTransaction ,
506
545
usdc: polygonTransaction ,
507
546
eur: euroSettlement ,
547
+ crc: crcSettlement ,
508
548
refundTx: refundTransaction ,
509
549
};
510
550
@@ -522,10 +562,10 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
522
562
523
563
protected _getOasisRecipientPublicKey() {
524
564
// note that this method gets overwritten for SetupSwapLedger
525
- if (! this .keyguardResult || ! this .keyguardResult .eurPubKey ) {
565
+ if (! this .keyguardResult || ! this .keyguardResult .fiatPubKey ) {
526
566
throw new Error (' Cannot find OASIS recipient public key' );
527
567
}
528
- return Nimiq .BufferUtils .toBase64Url (Nimiq .BufferUtils .fromHex (this .keyguardResult .eurPubKey ))
568
+ return Nimiq .BufferUtils .toBase64Url (Nimiq .BufferUtils .fromHex (this .keyguardResult .fiatPubKey ))
529
569
.replace (/ \. * $ / , ' ' ); // OASIS cannot handle trailing filler dots
530
570
}
531
571
@@ -535,6 +575,7 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
535
575
btc? : SignedBtcTransaction ,
536
576
usdc? : SignedPolygonTransaction ,
537
577
eur? : string ,
578
+ crc? : string ,
538
579
refundTx? : string ,
539
580
} | null > {
540
581
// Note that this method gets overwritten for SetupSwapLedger
@@ -550,6 +591,7 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
550
591
btc : bitcoinTransaction,
551
592
usdc : polygonTransaction,
552
593
eur : euroSettlement,
594
+ crc : crcSettlement,
553
595
refundTx,
554
596
} = await client .signSwapTransactions (keyguardRequest );
555
597
@@ -584,6 +626,7 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView {
584
626
} : undefined ,
585
627
usdc: polygonTransaction ,
586
628
eur: euroSettlement ,
629
+ crc: crcSettlement ,
587
630
refundTx ,
588
631
};
589
632
}
0 commit comments