Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(csi-1170): fix supportedCurrencies check for RECEIVE amountType #542

Merged
merged 47 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
9548938
fix: supportedCurrencies for RECEIVE amountType
oderayi Feb 5, 2025
5a12bda
chore(snapshot): 24.0.7-snapshot.0
oderayi Feb 5, 2025
0b491a5
chore: update deps
oderayi Feb 5, 2025
0c9cbb1
chore(snapshot): 24.0.7-snapshot.1
oderayi Feb 5, 2025
166d18f
refactor: RECEIVE supportedCurrencies
oderayi Feb 5, 2025
cc2eb42
chore: revert version and some changes
oderayi Feb 5, 2025
ab87ffd
chore(snapshot): 24.0.7-snapshot.0
oderayi Feb 5, 2025
ab8bb65
chore(snapshot): 24.0.7-snapshot.1
oderayi Feb 5, 2025
fb21074
chore(snapshot): 24.0.7-snapshot.2
oderayi Feb 5, 2025
72a24bc
chore: restore files
oderayi Feb 5, 2025
f498fe2
chore: restore file
oderayi Feb 5, 2025
f3971c7
chore(snapshot): 24.0.7-snapshot.3
oderayi Feb 5, 2025
ae41cdb
chore: remove commented code
oderayi Feb 6, 2025
d5ec747
fix: update with vijay's feedback
oderayi Feb 6, 2025
6a5ba91
fix: update isFxNeeded condition
oderayi Feb 6, 2025
b6ad595
fix: update fx condition
oderayi Feb 6, 2025
322ba86
chore: restore tests
oderayi Feb 6, 2025
6f046eb
chore: remove commented code
oderayi Feb 6, 2025
06afc58
fix: update fx condition, restore func test
oderayi Feb 6, 2025
bd68a8f
chore: restore test
oderayi Feb 6, 2025
baaf663
chore: upgrade ci orb
oderayi Feb 6, 2025
a6b1f63
chore(snapshot): 24.0.7-snapshot.4
oderayi Feb 6, 2025
0f41f72
chore: upgrade ci orb
oderayi Feb 7, 2025
115e4d0
chore(snapshot): 24.0.7-snapshot.5
oderayi Feb 7, 2025
8343837
chore: downgrade ci orb
oderayi Feb 7, 2025
a3a7ed9
chore: update orb to latest
oderayi Feb 7, 2025
0293274
fix: update outbound post fxquotes dto, downgrade orb
oderayi Feb 7, 2025
102fd68
chore(snapshot): 24.0.7-snapshot.0
oderayi Feb 7, 2025
85d9884
chore: linting
oderayi Feb 7, 2025
99b6e44
chore(snapshot): 24.0.7-snapshot.1
oderayi Feb 7, 2025
5ab9cfe
fix: update RECIEVE logic in dto
oderayi Feb 7, 2025
4fdbbbc
chore(snapshot): 24.0.7-snapshot.2
oderayi Feb 7, 2025
29e73da
chore(snapshot): 24.0.7-snapshot.3
oderayi Feb 7, 2025
dff971d
chore(snapshot): 24.0.7-snapshot.4
oderayi Feb 7, 2025
aad59ba
chore(snapshot): 24.0.7-snapshot.5
oderayi Feb 7, 2025
5179a0f
chore(snapshot): 24.0.7-snapshot.6
oderayi Feb 7, 2025
ce66fd2
chore: snapshot
oderayi Feb 7, 2025
367d06a
chore(snapshot): 24.0.7-snapshot.7
oderayi Feb 7, 2025
cebb13c
chore(snapshot): 24.0.7-snapshot.8
oderayi Feb 7, 2025
54b2a15
ci: bump orb
oderayi Feb 7, 2025
ad1098f
chore(snapshot): 24.0.7-snapshot.9
oderayi Feb 7, 2025
eb73ab6
chore: revert version
oderayi Feb 10, 2025
2ae33ff
chore: update deps
oderayi Feb 10, 2025
ef921ee
chore: bump orb version
oderayi Feb 10, 2025
b0dafbd
chore: remove commented code
oderayi Feb 10, 2025
973216c
Merge branch 'master' of github.com:mojaloop/sdk-scheme-adapter into …
oderayi Feb 10, 2025
84f0658
Merge branch 'master' of github.com:mojaloop/sdk-scheme-adapter into …
oderayi Feb 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1
setup: true
orbs:
build: mojaloop/[email protected].50
build: mojaloop/[email protected].55
workflows:
setup:
jobs:
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.pm4ml.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.7'

services:

sdk-scheme-adapter-api-svc:
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
networks:
mojaloop-net:
name: mojaloop-net
Expand Down
2 changes: 1 addition & 1 deletion modules/api-svc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/sdk-scheme-adapter-api-svc",
"version": "21.0.0-snapshot.1",
"version": "21.0.0-snapshot.19",
"description": "An adapter for connecting to Mojaloop API enabled switches.",
"main": "src/index.js",
"types": "src/index.d.ts",
Expand Down
49 changes: 33 additions & 16 deletions modules/api-svc/src/lib/dto.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/*eslint quote-props: ["error", "as-needed"]*/
const config = require('../config');
const randomUUID = require('@mojaloop/central-services-shared').Util.id(config.idGenerator);
const { Directions, SDKStateEnum} = require('./model/common');
const { Directions, SDKStateEnum, AmountTypes } = require('./model/common');

const quoteRequestStateDto = (request) => ({
// transferId: this follows the slightly dodgy assumption that transferId will be same as this transactionId.
Expand Down Expand Up @@ -56,24 +56,41 @@ const fxQuoteRequestStateDto = (request) => ({
* @param data {object} - "state" of inbound transaction request
* Supports only single FXP and currency for now
*/
const outboundPostFxQuotePayloadDto = (data) => Object.freeze({
conversionRequestId: randomUUID(),
conversionTerms: {
conversionId: randomUUID(), // should be the same as commitRequestId from fxTransfer
initiatingFsp: data.from.fspId,
determiningTransferId: data.transferId,
counterPartyFsp: data.fxProviders[0],
amountType: data.amountType,
sourceAmount: {
const outboundPostFxQuotePayloadDto = (data) => {
let sourceAmount, targetAmount;

sourceAmount = {
currency: data.currency,
amount: data.amount
};
targetAmount = {
currency: data.supportedCurrencies[0],
};

if (data.amountType === AmountTypes.RECEIVE && !config.supportedCurrencies.includes(data.currency)) {
sourceAmount = {
currency: config.supportedCurrencies[0],
};
targetAmount = {
currency: data.currency,
amount: data.amount
},
targetAmount: {
currency: data.supportedCurrencies[0],
},
expiration: data.fxQuoteExpiration,
};
}
});

return Object.freeze({
conversionRequestId: randomUUID(),
conversionTerms: {
conversionId: randomUUID(), // should be the same as commitRequestId from fxTransfer
initiatingFsp: data.from.fspId,
determiningTransferId: data.transferId,
counterPartyFsp: data.fxProviders[0],
amountType: data.amountType,
sourceAmount,
targetAmount,
expiration: data.fxQuoteExpiration,
}
});
};

/**
* @param data {object} - "state" of inbound transaction request
Expand Down
33 changes: 31 additions & 2 deletions modules/api-svc/src/lib/model/OutboundTransfersModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class OutboundTransfersModel {
this._multiplePartiesResponseSeconds = config.multiplePartiesResponseSeconds;
this._sendFinalNotificationIfRequested = config.sendFinalNotificationIfRequested;
this._apiType = config.apiType;
this._supportedCurrencies = config.supportedCurrencies;

if (this._autoAcceptParty && this._multiplePartiesResponse) {
throw new Error('Conflicting config options provided: autoAcceptParty and multiplePartiesResponse');
Expand Down Expand Up @@ -391,13 +392,13 @@ class OutboundTransfersModel {
}
this.data.to.dateOfBirth = payee.personalInfo.dateOfBirth;
}

if (Array.isArray(payee.supportedCurrencies)) {
if (!payee.supportedCurrencies.length) {
throw new Error(ErrorMessages.noSupportedCurrencies);
}

this.data.needFx = !payee.supportedCurrencies.includes(this.data.currency);
this.data.needFx = this._isFxNeeded(this._supportedCurrencies, payee.supportedCurrencies, this.data.currency, this.data.amountType);
this.data.supportedCurrencies = payee.supportedCurrencies;
}

Expand Down Expand Up @@ -1210,6 +1211,34 @@ class OutboundTransfersModel {
return modifiedData;
}

/**
* Determines if FX is needed for the transfer
*
* @param {Array} payerCurrencies - Array of supported currencies for the payer
* @param {Array} payeeCurrencies - Array of supported currencies for the payee
* @param {string} amountCurrency - Currency of the amount being transferred
* @param {string} amountType - Type of the amount being transferred (SEND/RECEIVE)
* @returns {boolean} - true if FX is needed, false if not
*/
_isFxNeeded(payerCurrencies, payeeCurrencies, amountCurrency, amountType) {
if (payerCurrencies.includes(amountCurrency) && payeeCurrencies.includes(amountCurrency)) {
return false;
}
const intersection = payerCurrencies.filter(currency => payeeCurrencies.includes(currency));
if(intersection.length > 0 && !intersection.includes(amountCurrency)) {
return true;
}
if (amountType === AmountTypes.RECEIVE) {
if (!payerCurrencies.includes(amountCurrency)) {
return true;
}
}
if (!payeeCurrencies.includes(amountCurrency)) {
return true;
}

return false;
}

/**
* Loads a transfer model from cache for resumption of the transfer process
Expand Down
2 changes: 1 addition & 1 deletion modules/api-svc/src/lib/model/common/Enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const ErrorMessages = Object.freeze({
noSupportedCurrencies: 'No payee supportedCurrencies received',
responseMissedExpiryDeadline: 'Response missed expiry deadline',
quoteRejectedByBackend: 'Quote rejected by backend',
fxQuoteRejectedByBackend: 'FX quote rejected by backend',
fxQuoteRejectedByBackend: 'FX quote rejected by backend'
});

const AmountTypes = Object.freeze({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@
"port": 4004
},
"getServicesFxpResponse": ["fxp_id"],
"apiType": "fspiop"
"apiType": "fspiop",
"supportedCurrencies": ["XXX"]
}
2 changes: 1 addition & 1 deletion modules/outbound-command-event-handler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/sdk-scheme-adapter-outbound-command-event-handler",
"version": "0.3.0-snapshot.1",
"version": "0.3.0-snapshot.18",
"description": "Mojaloop sdk scheme adapter command event handler",
"license": "Apache-2.0",
"homepage": "https://github.com/mojaloop/sdk-scheme-adapter/",
Expand Down
2 changes: 1 addition & 1 deletion modules/outbound-domain-event-handler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/sdk-scheme-adapter-outbound-domain-event-handler",
"version": "0.3.0-snapshot.1",
"version": "0.3.0-snapshot.18",
"description": "mojaloop sdk scheme adapter outbound domain event handler",
"license": "Apache-2.0",
"homepage": "https://github.com/mojaloop/sdk-scheme-adapter/",
Expand Down
4 changes: 2 additions & 2 deletions modules/private-shared-lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion modules/private-shared-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/sdk-scheme-adapter-private-shared-lib",
"version": "0.4.0-snapshot.1",
"version": "0.4.0-snapshot.18",
"description": "SDK Scheme Adapter private shared library.",
"license": "Apache-2.0",
"homepage": "https://github.com/mojaloop/accounts-and-balances-bc/tree/main/modules/private-types",
Expand Down
1 change: 0 additions & 1 deletion test/func/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
networks:
mojaloop-net:
name: mojaloop-net
Expand Down
1 change: 0 additions & 1 deletion test/func/ttk-tests-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
networks:
mojaloop-net:
name: mojaloop-net
Expand Down