@@ -5566,23 +5566,58 @@ export class WalletService implements IWalletService {
5566
5566
} ) ;
5567
5567
}
5568
5568
5569
+ rampGetSellQuote ( req ) : Promise < any > {
5570
+ return new Promise ( ( resolve , reject ) => {
5571
+ const keys = this . rampGetKeys ( req ) ;
5572
+ const API = keys . API ;
5573
+ const API_KEY = keys . API_KEY ;
5574
+
5575
+ /*
5576
+ * Although fiatValue and cryptoAmount are not both required, you need to pass one of them.
5577
+ * cryptoAmount - should be passed in token wei - e.g. for 1ETH cryptoAmount: 1000000000000000000
5578
+ * cryptoAmount?: string;
5579
+ * fiatValue?: number;
5580
+ */
5581
+ if ( ! checkRequired ( req . body , [ 'cryptoAssetSymbol' , 'fiatCurrency' ] ) || ( ! checkRequired ( req . body , [ 'fiatValue' ] ) && ! checkRequired ( req . body , [ 'cryptoAmount' ] ) ) ) {
5582
+ return reject ( new ClientError ( "Ramp's request missing arguments" ) ) ;
5583
+ }
5584
+
5585
+ const headers = {
5586
+ 'Content-Type' : 'application/json'
5587
+ } ;
5588
+
5589
+ const URL : string = API + `/host-api/v3/offramp/quote/all?hostApiKey=${ API_KEY } ` ;
5590
+
5591
+ this . request . post (
5592
+ URL ,
5593
+ {
5594
+ headers,
5595
+ body : req . body ,
5596
+ json : true
5597
+ } ,
5598
+ ( err , data ) => {
5599
+ if ( err ) {
5600
+ return reject ( err . body ? err . body : err ) ;
5601
+ } else {
5602
+ return resolve ( data . body ? data . body : data ) ;
5603
+ }
5604
+ }
5605
+ ) ;
5606
+ } ) ;
5607
+ }
5608
+
5569
5609
rampGetSignedPaymentUrl ( req ) : { urlWithSignature : string } {
5570
5610
const webRequiredParams = [
5571
- 'swapAsset' ,
5572
- 'userAddress' ,
5573
5611
'selectedCountryCode' ,
5574
- 'finalUrl' ,
5575
5612
] ;
5576
5613
const appRequiredParams = [
5577
- 'swapAsset' ,
5578
- 'swapAmount' ,
5579
5614
'enabledFlows' ,
5580
5615
'defaultFlow' ,
5581
- 'userAddress' ,
5582
5616
'selectedCountryCode' ,
5583
5617
'defaultAsset' ,
5584
- 'finalUrl' ,
5585
5618
] ;
5619
+ const extraRequiredParams = req . body . flow && req . body . flow === 'sell' ? [ 'offrampAsset' ] : [ 'finalUrl' , 'userAddress' , 'swapAmount' , 'swapAsset' ] ;
5620
+ appRequiredParams . concat ( extraRequiredParams ) ;
5586
5621
5587
5622
const requiredParams = req . body . context === 'web' ? webRequiredParams : appRequiredParams ;
5588
5623
const keys = this . rampGetKeys ( req ) ;
@@ -5601,10 +5636,11 @@ export class WalletService implements IWalletService {
5601
5636
5602
5637
let qs = [ ] ;
5603
5638
qs . push ( 'hostApiKey=' + API_KEY ) ;
5604
- qs . push ( 'swapAsset=' + encodeURIComponent ( req . body . swapAsset ) ) ;
5605
- qs . push ( 'userAddress=' + encodeURIComponent ( req . body . userAddress ) ) ;
5606
5639
qs . push ( 'selectedCountryCode=' + encodeURIComponent ( req . body . selectedCountryCode ) ) ;
5607
- qs . push ( 'finalUrl=' + encodeURIComponent ( req . body . finalUrl ) ) ;
5640
+ if ( req . body . finalUrl ) qs . push ( 'finalUrl=' + encodeURIComponent ( req . body . finalUrl ) ) ;
5641
+ if ( req . body . userAddress ) qs . push ( 'userAddress=' + encodeURIComponent ( req . body . userAddress ) ) ;
5642
+ if ( req . body . swapAsset ) qs . push ( 'swapAsset=' + encodeURIComponent ( req . body . swapAsset ) ) ;
5643
+ if ( req . body . offrampAsset ) qs . push ( 'offrampAsset=' + encodeURIComponent ( req . body . offrampAsset ) ) ;
5608
5644
if ( req . body . enabledFlows ) qs . push ( 'enabledFlows=' + encodeURIComponent ( req . body . enabledFlows ) ) ;
5609
5645
if ( req . body . defaultFlow ) qs . push ( 'defaultFlow=' + encodeURIComponent ( req . body . defaultFlow ) ) ;
5610
5646
if ( req . body . hostLogoUrl ) qs . push ( 'hostLogoUrl=' + encodeURIComponent ( req . body . hostLogoUrl ) ) ;
@@ -5614,6 +5650,11 @@ export class WalletService implements IWalletService {
5614
5650
if ( req . body . fiatCurrency ) qs . push ( 'fiatCurrency=' + encodeURIComponent ( req . body . fiatCurrency ) ) ;
5615
5651
if ( req . body . defaultAsset ) qs . push ( 'defaultAsset=' + encodeURIComponent ( req . body . defaultAsset ) ) ;
5616
5652
if ( req . body . userEmailAddress ) qs . push ( 'userEmailAddress=' + encodeURIComponent ( req . body . userEmailAddress ) ) ;
5653
+ if ( req . body . useSendCryptoCallback ) qs . push ( 'useSendCryptoCallback=' + encodeURIComponent ( req . body . useSendCryptoCallback ) ) ;
5654
+ if ( req . body . paymentMethodType ) qs . push ( 'paymentMethodType=' + encodeURIComponent ( req . body . paymentMethodType ) ) ;
5655
+ if ( req . body . hideExitButton ) qs . push ( 'hideExitButton=' + encodeURIComponent ( req . body . hideExitButton ) ) ;
5656
+ if ( req . body . variant ) qs . push ( 'variant=' + encodeURIComponent ( req . body . variant ) ) ;
5657
+ if ( req . body . useSendCryptoCallbackVersion ) qs . push ( 'useSendCryptoCallbackVersion=' + encodeURIComponent ( req . body . useSendCryptoCallbackVersion ) ) ;
5617
5658
5618
5659
const URL_SEARCH : string = `?${ qs . join ( '&' ) } ` ;
5619
5660
@@ -5634,6 +5675,7 @@ export class WalletService implements IWalletService {
5634
5675
let URL : string ;
5635
5676
5636
5677
let qs = [ ] ;
5678
+ // "Buy" and "Sell" features use the same properties. Use "flow" to target the correct endpoint
5637
5679
qs . push ( 'hostApiKey=' + API_KEY ) ;
5638
5680
if ( req . body . currencyCode ) qs . push ( 'currencyCode=' + encodeURIComponent ( req . body . currencyCode ) ) ;
5639
5681
if ( req . body . withDisabled ) qs . push ( 'withDisabled=' + encodeURIComponent ( req . body . withDisabled ) ) ;
@@ -5643,7 +5685,43 @@ export class WalletService implements IWalletService {
5643
5685
qs . push ( 'userIp=' + encodeURIComponent ( ip ) ) ;
5644
5686
}
5645
5687
5646
- URL = API + `/host-api/v3/assets?${ qs . join ( '&' ) } ` ;
5688
+ URL = API + `/host-api/v3${ req . body . flow && req . body . flow === 'sell' ? '/offramp' : '' } /assets?${ qs . join ( '&' ) } ` ;
5689
+
5690
+ this . request . get (
5691
+ URL ,
5692
+ {
5693
+ headers,
5694
+ json : true
5695
+ } ,
5696
+ ( err , data ) => {
5697
+ if ( err ) {
5698
+ return reject ( err . body ? err . body : err ) ;
5699
+ } else {
5700
+ return resolve ( data . body ? data . body : data ) ;
5701
+ }
5702
+ }
5703
+ ) ;
5704
+ } ) ;
5705
+ }
5706
+
5707
+ rampGetSellTransactionDetails ( req ) : Promise < any > {
5708
+ return new Promise ( ( resolve , reject ) => {
5709
+ const keys = this . rampGetKeys ( req ) ;
5710
+ const API = keys . API ;
5711
+
5712
+ if ( ! checkRequired ( req . body , [ 'id' , 'saleViewToken' ] ) ) {
5713
+ return reject ( new ClientError ( "Ramp's request missing arguments" ) ) ;
5714
+ }
5715
+
5716
+ const headers = {
5717
+ 'Content-Type' : 'application/json'
5718
+ } ;
5719
+ let URL : string ;
5720
+
5721
+ let qs = [ ] ;
5722
+ qs . push ( 'secret=' + req . body . saleViewToken ) ;
5723
+
5724
+ URL = API + `/host-api/v3/offramp/sale/${ req . body . id } ?${ qs . join ( '&' ) } ` ;
5647
5725
5648
5726
this . request . get (
5649
5727
URL ,
0 commit comments