Skip to content

Commit

Permalink
Some improvements in settlements demo (#111)
Browse files Browse the repository at this point in the history
* Some improvements in settlements demo

* Bumped up the version
  • Loading branch information
vijayg10 committed Jul 21, 2021
1 parent da44096 commit 3c79824
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 22 deletions.
2 changes: 1 addition & 1 deletion 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ml-testing-toolkit-ui",
"version": "13.1.0",
"version": "13.1.1",
"description": "Mojaloop Testing Toolkit Web User Interface",
"main": "index.js",
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions src/services/demos/MobileSimulator/mojaloopOutbound.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class OutboundService {
// Replace corresponding values in inputValues
template.inputValues.amount = amount + ''
template.inputValues.currency = currency + ''
template.inputValues.fromFirstName = 'Vijay'
template.inputValues.fromLastName = 'Kumar'
const resp = await axios.post(this.apiBaseUrl + "/api/outbound/template/" + traceId, template , { headers: { 'Content-Type': 'application/json' } })
// if(typeof response.data === 'object') {
// return response.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
"if(environment.winstate===\"PENDING_SETTLEMENT\"){",
"",
"res.participants.map(function (participant) {",
" participant.accounts.filter(account => account.netSettlementAmount.currency === environment.SIMPAYER_CURRENCY).forEach(curAccount => {",
" participant.accounts.forEach(curAccount => {",
"//for(const curAccount of account) { ",
"",
" dfspsacc[i] = {",
Expand Down Expand Up @@ -324,7 +324,7 @@
" console.log(\"Window is empty\")",
"}",
"/*res.participants.map(participant => {",
" participant.accounts.filter(account => account.netSettlementAmount.currency === pm.environment.get('SIMPAYER_CURRENCY'))",
" participant.accounts",
" .forEach(curAccount => {*/",
" "
]
Expand Down Expand Up @@ -383,7 +383,7 @@
"",
"",
"res.participants.map(function (participant) {",
" participant.accounts.filter(account => account.netSettlementAmount.currency === environment.SIMPAYER_CURRENCY).forEach(curAccount => {",
" participant.accounts.forEach(curAccount => {",
"//for(const curAccount of account) { ",
"",
" dfspsacc[i] = {",
Expand Down Expand Up @@ -419,7 +419,7 @@
" console.log(\"Window is empty\")",
"}",
"/*res.participants.map(participant => {",
" participant.accounts.filter(account => account.netSettlementAmount.currency === pm.environment.get('SIMPAYER_CURRENCY'))",
" participant.accounts",
" .forEach(curAccount => {*/",
" "
]
Expand Down Expand Up @@ -473,7 +473,7 @@
"",
"",
"res.participants.map(function (participant) {",
" participant.accounts.filter(account => account.netSettlementAmount.currency === environment.SIMPAYER_CURRENCY).forEach(curAccount => {",
" participant.accounts.forEach(curAccount => {",
"//for(const curAccount of account) { ",
"",
" dfspsacc[i] = {",
Expand Down Expand Up @@ -509,7 +509,7 @@
" console.log(\"Window is empty\")",
"}",
"/*res.participants.map(participant => {",
" participant.accounts.filter(account => account.netSettlementAmount.currency === pm.environment.get('SIMPAYER_CURRENCY'))",
" participant.accounts",
" .forEach(curAccount => {*/",
" "
]
Expand Down Expand Up @@ -563,7 +563,7 @@
"",
"",
"res.participants.map(function (participant) {",
" participant.accounts.filter(account => account.netSettlementAmount.currency === environment.SIMPAYER_CURRENCY).forEach(curAccount => {",
" participant.accounts.forEach(curAccount => {",
"//for(const curAccount of account) { ",
"",
" dfspsacc[i] = {",
Expand Down
154 changes: 154 additions & 0 deletions src/services/demos/MobileSimulator/template_provisioning.json
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,83 @@
}
]
}
},
{
"id": 27,
"description": "Add participant second currency",
"apiVersion": {
"minorVersion": 3,
"majorVersion": 9,
"type": "central_admin"
},
"operationPath": "/participants",
"path": "/participants",
"method": "post",
"body": {
"name": "{$inputs.mobileSimPayerFsp}",
"currency": "{$inputs.currency2}"
},
"headers": {
"Content-Type": "application/json"
},
"url": "{$inputs.HOST_CENTRAL_LEDGER}",
"tests": {
"assertions": [
{
"id": 1,
"description": "status to be 201 if not exists or 400 if exists",
"exec": [
"if (response.body.errorInformation) {",
" expect(response.status).to.equal(400)",
"} else {",
" expect(response.status).to.equal(201)",
"}"
]
}
]
}
},
{
"id": 28,
"description": "Add initial position and limits second currency",
"apiVersion": {
"minorVersion": 3,
"majorVersion": 9,
"type": "central_admin"
},
"operationPath": "/participants/{name}/initialPositionAndLimits",
"path": "/participants/{$inputs.mobileSimPayerFsp}/initialPositionAndLimits",
"method": "post",
"params": {
"name": "{$inputs.mobileSimPayerFsp}"
},
"body": {
"currency": "{$inputs.currency2}",
"limit": {
"type": "NET_DEBIT_CAP",
"value": 1000000
},
"initialPosition": 0
},
"headers": {
"Content-Type": "application/json"
},
"url": "{$inputs.HOST_CENTRAL_LEDGER}",
"tests": {
"assertions": [
{
"id": 1,
"description": "status to be 201 if not exists or 500 if exists",
"exec": [
"if (response.body.errorInformation) {",
" expect(response.status).to.equal(500)",
"} else {",
" expect(response.status).to.equal(201)",
"}"
]
}
]
}
}
]
},
Expand Down Expand Up @@ -1796,6 +1873,83 @@
}
]
}
},
{
"id": 27,
"description": "Add participant second currency",
"apiVersion": {
"minorVersion": 3,
"majorVersion": 9,
"type": "central_admin"
},
"operationPath": "/participants",
"path": "/participants",
"method": "post",
"body": {
"name": "{$inputs.mobileSimPayeeFsp}",
"currency": "{$inputs.currency2}"
},
"headers": {
"Content-Type": "application/json"
},
"url": "{$inputs.HOST_CENTRAL_LEDGER}",
"tests": {
"assertions": [
{
"id": 1,
"description": "status to be 201 if not exists or 400 if exists",
"exec": [
"if (response.body.errorInformation) {",
" expect(response.status).to.equal(400)",
"} else {",
" expect(response.status).to.equal(201)",
"}"
]
}
]
}
},
{
"id": 28,
"description": "Add initial position and limits second currency",
"apiVersion": {
"minorVersion": 3,
"majorVersion": 9,
"type": "central_admin"
},
"operationPath": "/participants/{name}/initialPositionAndLimits",
"path": "/participants/{$inputs.mobileSimPayeeFsp}/initialPositionAndLimits",
"method": "post",
"params": {
"name": "{$inputs.mobileSimPayeeFsp}"
},
"body": {
"currency": "{$inputs.currency2}",
"limit": {
"type": "NET_DEBIT_CAP",
"value": 1000000
},
"initialPosition": 0
},
"headers": {
"Content-Type": "application/json"
},
"url": "{$inputs.HOST_CENTRAL_LEDGER}",
"tests": {
"assertions": [
{
"id": 1,
"description": "status to be 201 if not exists or 500 if exists",
"exec": [
"if (response.body.errorInformation) {",
" expect(response.status).to.equal(500)",
"} else {",
" expect(response.status).to.equal(201)",
"}"
]
}
]
}
}
]
}
Expand Down
15 changes: 15 additions & 0 deletions src/utils/styleHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,18 @@ export const TTKColors = {
assertionFailed: '#f50',
assertionSkipped: '#f4c10b', // Or use #D7D700
}

export const hashRGB = (str) => {
// Calculage hash
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 12) - hash);
}

var c = (hash & 0xFFFFFF)
.toString(16)
.toUpperCase();
console.log(c, hash)

return '#' + "00000".substring(0, 6 - c.length) + c;
}
18 changes: 10 additions & 8 deletions src/views/demos/MobileSimulator/HUBConsole.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
******/
import React from "react";
import { Row, Col, Typography, Button, Table, Tag, Progress, Descriptions, Select } from 'antd';
import { hashRGB } from '../../../utils/styleHelpers'
const { Text, Title } = Typography
const { Option } = Select;

Expand Down Expand Up @@ -237,20 +238,21 @@ class HUBConsole extends React.Component {

const dfspValuesData = Object.entries(this.state.dfsps).map((dfspItem,index) => {
const positionData = dfspItem[1].accountsData.filter(item => item.ledgerAccountType === 'POSITION').reduce((prevVal,currVal,idx) => {
const detail = currVal.currency + ': ' + currVal.value
return idx == 0 ? detail : prevVal + ', ' + detail
const detail = <Tag color={hashRGB(currVal.currency)}>{currVal.currency + ': ' + currVal.value}</Tag>
return idx == 0 ? detail : (<>{prevVal}<br />{detail}</>)
}, '')
const netDebitCapData = dfspItem[1].NET_DEBIT_CAP && Object.entries(dfspItem[1].NET_DEBIT_CAP).reduce((prevVal,currVal,idx) => {
const detail = currVal[0] + ': ' + currVal[1]
return idx == 0 ? detail : prevVal + ', ' + detail
const detail = <Tag color={hashRGB(currVal[0])}>{currVal[0] + ': ' + currVal[1]}</Tag>
return idx == 0 ? detail : (<>{prevVal}<br />{detail}</>)
}, '')
const settlementData = dfspItem[1].accountsData.filter(item => item.ledgerAccountType === 'SETTLEMENT').reduce((prevVal,currVal,idx) => {
const detail = currVal.currency + ': ' + currVal.value
return idx == 0 ? detail : prevVal + ', ' + detail
const detail = <Tag color={hashRGB(currVal.currency)}>{currVal.currency + ': ' + currVal.value}</Tag>
// const detail = currVal.currency + ': ' + currVal.value
return idx == 0 ? detail : (<>{prevVal}<br />{detail}</>)
}, '')
const interchangeFeeData = dfspItem[1].accountsData.filter(item => item.ledgerAccountType === 'INTERCHANGE_FEE').reduce((prevVal,currVal,idx) => {
const detail = currVal.currency + ': ' + currVal.value
return idx == 0 ? detail : prevVal + ', ' + detail
const detail = <Tag color={hashRGB(currVal.currency)}>{currVal.currency + ': ' + currVal.value}</Tag>
return idx == 0 ? detail : (<>{prevVal}<br />{detail}</>)
}, '')
return {
key: index,
Expand Down
8 changes: 4 additions & 4 deletions src/views/demos/MobileSimulator/PayeeMobile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PayeeMobile extends React.Component {
}

resetState = () => {
this.setState({receivedAmount: null, payerComplexName: null, stage: null})
this.setState({receivedAmount: null, payeeReceiveAmount: null, payerComplexName: null, stage: null})
}

handleNotificationEvents = (event) => {
Expand Down Expand Up @@ -70,7 +70,7 @@ class PayeeMobile extends React.Component {
// }
case 'payeePutQuotes':
{
this.setState({payeeReceiveAmount: event.data.requestBody && event.data.requestBody.payeeReceiveAmount && event.data.requestBody.payeeReceiveAmount.amount})
this.setState({payeeReceiveAmount: event.data.requestBody && event.data.requestBody.payeeReceiveAmount})
break
}
// case 'payeePutQuotesResponse':
Expand Down Expand Up @@ -109,8 +109,8 @@ class PayeeMobile extends React.Component {
<Col span={24} className='text-center'>
<Result
status="success"
title={'Received ' + this.state.receivedAmount}
subTitle={'from ' + this.state.payerComplexName.lastName}
title={'Received ' + this.state.receivedAmount.amount + ' ' + this.state.receivedAmount.currency}
subTitle={'from ' + this.state.payerComplexName.firstName}
/>
</Col>
</Row>
Expand Down
2 changes: 1 addition & 1 deletion src/views/demos/MobileSimulator/PayerMobile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class PayerMobile extends React.Component {
? (
<Result
status="success"
title={'Sent $' + this.state.amount}
title={'Sent ' + this.state.amount + ' ' + this.state.selectedCurrency}
subTitle={this.state.partyInfo && this.state.partyInfo.personalInfo && this.state.partyInfo.personalInfo.complexName && 'to ' + this.state.partyInfo.personalInfo.complexName.lastName}
/>
)
Expand Down

0 comments on commit 3c79824

Please sign in to comment.