@transferwise/comparison-components 20.1.1 → 20.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/es/{ComparisonTableHeroContainer-533453be.js → ComparisonTableHeroContainer-53d39603.js} +2 -2
- package/dist/es/{ComparisonTableHeroContainer-533453be.js.map → ComparisonTableHeroContainer-53d39603.js.map} +1 -1
- package/dist/es/{ErrorTemplate-74613c10.js → ErrorTemplate-41caf019.js} +2 -2
- package/dist/es/{ErrorTemplate-74613c10.js.map → ErrorTemplate-41caf019.js.map} +1 -1
- package/dist/es/{ProviderComparisonTable-286e4ec1.js → ProviderComparisonTable-3bad485c.js} +2 -2
- package/dist/es/{ProviderComparisonTable-286e4ec1.js.map → ProviderComparisonTable-3bad485c.js.map} +1 -1
- package/dist/es/{ReceiveAmount-b4e9912d.js → ReceiveAmount-49a2596d.js} +2 -2
- package/dist/es/{ReceiveAmount-b4e9912d.js.map → ReceiveAmount-49a2596d.js.map} +1 -1
- package/dist/es/{TravelMoney-de43d7df.js → TravelMoney-4298a774.js} +2 -2
- package/dist/es/{TravelMoney-de43d7df.js.map → TravelMoney-4298a774.js.map} +1 -1
- package/dist/es/comparison/index.js +1 -1
- package/dist/es/comparison-table/index.js +1 -1
- package/dist/es/comparison-table-hero/index.js +1 -1
- package/dist/es/{index-669310ed.js → index-114e385c.js} +2 -2
- package/dist/es/{index-669310ed.js.map → index-114e385c.js.map} +1 -1
- package/dist/es/index.js +1 -1
- package/dist/es/provider-comparison-table/index.js +1 -1
- package/dist/es/provider-comparison-widget/index.js +1 -1
- package/dist/es/transformQuotesResponseV2.js +1 -1
- package/dist/es/travel-money/index.js +1 -1
- package/dist/umd/comparison-components.css +1 -1
- package/dist/umd/comparison-components.js +4 -4
- package/dist/umd/comparison-components.js.map +1 -1
- package/package.json +1 -1
- package/src/resources/clients/quotes/__test__/transformQuotesResponseV2.spec.ts +177 -0
- package/src/resources/clients/quotes/currenciesWithoutDecimals.ts +28 -0
- package/src/resources/clients/quotes/transformQuotesResponseV2.ts +15 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/comparison-components",
|
|
3
|
-
"version": "20.1.
|
|
3
|
+
"version": "20.1.5",
|
|
4
4
|
"description": "Display a comparison table of providers given a route and amount.",
|
|
5
5
|
"homepage": "https://wise.com/gb/compare/",
|
|
6
6
|
"main": "dist/umd/comparison-components.js",
|
|
@@ -483,4 +483,181 @@ describe('quotes v3 response transformations to the canonical model V2', () => {
|
|
|
483
483
|
|
|
484
484
|
expect(transformQuotesResponseV2(providers, wiseProvider)).toStrictEqual(expected);
|
|
485
485
|
});
|
|
486
|
+
|
|
487
|
+
it('given a route with a small send amount with a decimal currency, and provider does have a hidden fee, do show the hidden fee', () => {
|
|
488
|
+
const wiseProvider = {
|
|
489
|
+
...wiseQuoteApiAdjusted,
|
|
490
|
+
rate: 0.88665,
|
|
491
|
+
};
|
|
492
|
+
const providers = {
|
|
493
|
+
providers: [
|
|
494
|
+
{
|
|
495
|
+
name: 'Western Union',
|
|
496
|
+
alias: 'western-union',
|
|
497
|
+
logo: 'https://dq8dwmysp7hk1.cloudfront.net/logos/western-union.svg',
|
|
498
|
+
partner: true,
|
|
499
|
+
quotes: [
|
|
500
|
+
{
|
|
501
|
+
rate: 0.00759645,
|
|
502
|
+
fee: 0,
|
|
503
|
+
dateCollected: new Date('2018-10-23T12:03:27'),
|
|
504
|
+
receivedAmount: 21.67,
|
|
505
|
+
},
|
|
506
|
+
],
|
|
507
|
+
},
|
|
508
|
+
],
|
|
509
|
+
sendAmount: 25,
|
|
510
|
+
sourceCurrency: 'USD',
|
|
511
|
+
targetCurrency: 'EUR',
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
const expected = {
|
|
515
|
+
quotes: [
|
|
516
|
+
{
|
|
517
|
+
provider: {
|
|
518
|
+
name: 'Western Union',
|
|
519
|
+
alias: 'western-union',
|
|
520
|
+
logoUrl: 'https://dq8dwmysp7hk1.cloudfront.net/logos/western-union.svg',
|
|
521
|
+
partner: true,
|
|
522
|
+
},
|
|
523
|
+
route: {
|
|
524
|
+
sourceCurrency: 'USD',
|
|
525
|
+
targetCurrency: 'EUR',
|
|
526
|
+
},
|
|
527
|
+
rate: 0.00759645,
|
|
528
|
+
fees: {
|
|
529
|
+
breakdown: [
|
|
530
|
+
{
|
|
531
|
+
type: FeeType.HIDDEN,
|
|
532
|
+
amount: { value: 0.55, currency: 'USD' },
|
|
533
|
+
},
|
|
534
|
+
],
|
|
535
|
+
total: { value: 0.55, currency: 'USD' },
|
|
536
|
+
},
|
|
537
|
+
receiveAmount: { value: 21.67, currency: 'EUR' },
|
|
538
|
+
sendAmount: { value: 25, currency: 'USD' },
|
|
539
|
+
},
|
|
540
|
+
],
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
expect(transformQuotesResponseV2(providers, wiseProvider)).toStrictEqual(expected);
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
it('given a route with a small send amount with a non-decimal currency as source, and provider doesnt have a hidden fee, dont show the hidden fee', () => {
|
|
547
|
+
const wiseProvider = {
|
|
548
|
+
...wiseQuoteApiAdjusted,
|
|
549
|
+
rate: 0.0000612414,
|
|
550
|
+
};
|
|
551
|
+
const providers = {
|
|
552
|
+
providers: [
|
|
553
|
+
{
|
|
554
|
+
name: 'Western Union',
|
|
555
|
+
alias: 'western-union',
|
|
556
|
+
logo: 'https://dq8dwmysp7hk1.cloudfront.net/logos/western-union.svg',
|
|
557
|
+
partner: true,
|
|
558
|
+
quotes: [
|
|
559
|
+
{
|
|
560
|
+
rate: 0.00759645,
|
|
561
|
+
fee: 12175,
|
|
562
|
+
dateCollected: new Date('2018-10-23T12:03:27'),
|
|
563
|
+
receivedAmount: 0.17,
|
|
564
|
+
},
|
|
565
|
+
],
|
|
566
|
+
},
|
|
567
|
+
],
|
|
568
|
+
sendAmount: 15000,
|
|
569
|
+
sourceCurrency: 'IDR',
|
|
570
|
+
targetCurrency: 'EUR',
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
const expected = {
|
|
574
|
+
quotes: [
|
|
575
|
+
{
|
|
576
|
+
provider: {
|
|
577
|
+
name: 'Western Union',
|
|
578
|
+
alias: 'western-union',
|
|
579
|
+
logoUrl: 'https://dq8dwmysp7hk1.cloudfront.net/logos/western-union.svg',
|
|
580
|
+
partner: true,
|
|
581
|
+
},
|
|
582
|
+
route: {
|
|
583
|
+
sourceCurrency: 'IDR',
|
|
584
|
+
targetCurrency: 'EUR',
|
|
585
|
+
},
|
|
586
|
+
rate: 0.00759645,
|
|
587
|
+
fees: {
|
|
588
|
+
breakdown: [
|
|
589
|
+
{
|
|
590
|
+
type: FeeType.MARKETED,
|
|
591
|
+
amount: { value: 12175, currency: 'IDR' },
|
|
592
|
+
},
|
|
593
|
+
],
|
|
594
|
+
total: { value: 12175, currency: 'IDR' },
|
|
595
|
+
},
|
|
596
|
+
receiveAmount: { value: 0.17, currency: 'EUR' },
|
|
597
|
+
sendAmount: { value: 15000, currency: 'IDR' },
|
|
598
|
+
},
|
|
599
|
+
],
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
expect(transformQuotesResponseV2(providers, wiseProvider)).toStrictEqual(expected);
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
it('given a route with a small send amount with a non-decimal currency as target, and provider doesnt have a hidden fee, dont show the hidden fee', () => {
|
|
606
|
+
const wiseProvider = {
|
|
607
|
+
...wiseQuoteApiAdjusted,
|
|
608
|
+
rate: 0.0000612414,
|
|
609
|
+
};
|
|
610
|
+
const providers = {
|
|
611
|
+
providers: [
|
|
612
|
+
{
|
|
613
|
+
name: 'Western Union',
|
|
614
|
+
alias: 'western-union',
|
|
615
|
+
logo: 'https://dq8dwmysp7hk1.cloudfront.net/logos/western-union.svg',
|
|
616
|
+
partner: true,
|
|
617
|
+
quotes: [
|
|
618
|
+
{
|
|
619
|
+
rate: 0.00759645,
|
|
620
|
+
fee: 1.31,
|
|
621
|
+
dateCollected: new Date('2018-10-23T12:03:27'),
|
|
622
|
+
receivedAmount: 253,
|
|
623
|
+
},
|
|
624
|
+
],
|
|
625
|
+
},
|
|
626
|
+
],
|
|
627
|
+
sendAmount: 3,
|
|
628
|
+
sourceCurrency: 'GBP',
|
|
629
|
+
targetCurrency: 'JPY',
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
const expected = {
|
|
633
|
+
quotes: [
|
|
634
|
+
{
|
|
635
|
+
provider: {
|
|
636
|
+
name: 'Western Union',
|
|
637
|
+
alias: 'western-union',
|
|
638
|
+
logoUrl: 'https://dq8dwmysp7hk1.cloudfront.net/logos/western-union.svg',
|
|
639
|
+
partner: true,
|
|
640
|
+
},
|
|
641
|
+
route: {
|
|
642
|
+
sourceCurrency: 'GBP',
|
|
643
|
+
targetCurrency: 'JPY',
|
|
644
|
+
},
|
|
645
|
+
rate: 0.00759645,
|
|
646
|
+
fees: {
|
|
647
|
+
breakdown: [
|
|
648
|
+
{
|
|
649
|
+
type: FeeType.MARKETED,
|
|
650
|
+
amount: { value: 1.31, currency: 'GBP' },
|
|
651
|
+
},
|
|
652
|
+
],
|
|
653
|
+
total: { value: 1.31, currency: 'GBP' },
|
|
654
|
+
},
|
|
655
|
+
receiveAmount: { value: 253, currency: 'JPY' },
|
|
656
|
+
sendAmount: { value: 3, currency: 'GBP' },
|
|
657
|
+
},
|
|
658
|
+
],
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
expect(transformQuotesResponseV2(providers, wiseProvider)).toStrictEqual(expected);
|
|
662
|
+
});
|
|
486
663
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// From ISO 4217 (06/12/2021)
|
|
2
|
+
const CURRENCIES_WITHOUT_DECIMALS = new Set([
|
|
3
|
+
'CVE',
|
|
4
|
+
'IDR',
|
|
5
|
+
'ISK',
|
|
6
|
+
'BIF',
|
|
7
|
+
'CLP',
|
|
8
|
+
'DJF',
|
|
9
|
+
'GNF',
|
|
10
|
+
'ISK',
|
|
11
|
+
'JPY',
|
|
12
|
+
'KMF',
|
|
13
|
+
'KRW',
|
|
14
|
+
'PYG',
|
|
15
|
+
'RWF',
|
|
16
|
+
'UGX',
|
|
17
|
+
'UYI',
|
|
18
|
+
'VND',
|
|
19
|
+
'VUV',
|
|
20
|
+
'XAF',
|
|
21
|
+
'XOF',
|
|
22
|
+
'XPF',
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const isCurrencyWithoutDecimals = (currencyCode: string): boolean =>
|
|
26
|
+
CURRENCIES_WITHOUT_DECIMALS.has(currencyCode);
|
|
27
|
+
|
|
28
|
+
export default isCurrencyWithoutDecimals;
|
|
@@ -10,6 +10,7 @@ import TransferFeeComparisonQuote, {
|
|
|
10
10
|
} from '../../../transfer-fee-comparison/domain/Quote';
|
|
11
11
|
import TW_ALIAS from '../../provider-constants';
|
|
12
12
|
|
|
13
|
+
import isCurrencyWithoutDecimals from './currenciesWithoutDecimals';
|
|
13
14
|
import extractQuote from './extractQuote';
|
|
14
15
|
import extractWiseQuote from './extractWiseQuote';
|
|
15
16
|
|
|
@@ -18,29 +19,29 @@ export type TransformQuotesResponseType = {
|
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
function extractHiddenFeeInSourceCurrency(
|
|
22
|
+
targetCurrencyCode: string,
|
|
21
23
|
sendAmount: number,
|
|
22
24
|
receivedAmount: number,
|
|
23
25
|
marketedFee: number,
|
|
24
26
|
midmarketRate: number,
|
|
25
27
|
) {
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
+
const noDecimalsCurrencyTolerance = isCurrencyWithoutDecimals(targetCurrencyCode) ? 0.5 : 0;
|
|
29
|
+
const toleranceAmountInPercentage = 0.00001;
|
|
30
|
+
const expectedReceivedAmount = floorToTwoDecimalNumbers(
|
|
31
|
+
midmarketRate * (sendAmount - marketedFee) - noDecimalsCurrencyTolerance,
|
|
32
|
+
);
|
|
28
33
|
|
|
29
34
|
const receivedTheExpectedAmount = numberEqualsWithRelativeTolerance(
|
|
30
35
|
receivedAmount,
|
|
31
36
|
expectedReceivedAmount,
|
|
32
37
|
toleranceAmountInPercentage,
|
|
33
38
|
);
|
|
34
|
-
const receivedHigherThanExpected =
|
|
35
|
-
!receivedTheExpectedAmount && receivedAmount > expectedReceivedAmount;
|
|
36
|
-
|
|
37
|
-
const expectedHasMoreThanACentMissing = expectedReceivedAmount - receivedAmount >= 0.01;
|
|
39
|
+
const receivedHigherThanExpected = receivedAmount > expectedReceivedAmount;
|
|
38
40
|
|
|
39
|
-
const hasHiddenFee =
|
|
40
|
-
!receivedTheExpectedAmount && !receivedHigherThanExpected && expectedHasMoreThanACentMissing;
|
|
41
|
+
const hasHiddenFee = !receivedTheExpectedAmount && !receivedHigherThanExpected;
|
|
41
42
|
const hiddenFeePaidOnTargetCurrency = hasHiddenFee ? expectedReceivedAmount - receivedAmount : 0;
|
|
42
43
|
|
|
43
|
-
return parseFloat((hiddenFeePaidOnTargetCurrency
|
|
44
|
+
return parseFloat((hiddenFeePaidOnTargetCurrency / midmarketRate).toFixed(2));
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
function extractFees(
|
|
@@ -99,6 +100,7 @@ function buildQuoteObject(
|
|
|
99
100
|
midMarketRate: number,
|
|
100
101
|
) {
|
|
101
102
|
const hiddenFee: number = extractHiddenFeeInSourceCurrency(
|
|
103
|
+
quotesResults.targetCurrency,
|
|
102
104
|
quotesResults.sendAmount,
|
|
103
105
|
quote.receivedAmount,
|
|
104
106
|
quote.fee,
|
|
@@ -132,4 +134,8 @@ function buildQuoteObject(
|
|
|
132
134
|
};
|
|
133
135
|
}
|
|
134
136
|
|
|
137
|
+
function floorToTwoDecimalNumbers(value: number): number {
|
|
138
|
+
return Math.floor(value * 100) / 100;
|
|
139
|
+
}
|
|
140
|
+
|
|
135
141
|
export default transformQuotesResponseV2;
|