Skip to content

Commit

Permalink
fix(mu): create currency list for relay top up
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceJuliano committed Feb 7, 2025
1 parent fa128a9 commit 7144de1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions servers/mu/src/domain/clients/relay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('topUpWith function', function () {
logger.tap = () => (args) => {
return args
}
const fetchTransactionDetails = async () => {
const fetchTransactions = async () => {
return {
data: {
transactions: {
Expand All @@ -49,7 +49,7 @@ describe('topUpWith function', function () {
}
}
}
let topUp = topUpWith({ fetch, logger, wallet, address, fetchTransactionDetails })
let topUp = topUpWith({ fetch, logger, wallet, address, fetchTransactions })

it('should correctly sign and verify a request', async function () {
const params = {
Expand Down
10 changes: 10 additions & 0 deletions servers/mu/src/domain/lib/write-message-tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ export function writeMessageTxWith (env) {
if(!amount || !sender) {
return Rejected(new Error('Must set Sender and Quantity to top up.', { cause: ctx }))
}

if(!Object.keys(RELAY_MAP).includes("ALLOWED_CURRENCIES")) {
return Rejected(new Error('No allowed currencies configured on this MU.', { cause: ctx }))
}

if(!RELAY_MAP["ALLOWED_CURRENCIES"].includes("ALL")) {
if(!RELAY_MAP["ALLOWED_CURRENCIES"].includes(ctx.cachedMsg.fromProcessId)) {
return Rejected(new Error('This currency is not supported on this MU.', { cause: ctx }))
}
}

return topUp({ctx, relayUrl: RELAY_MAP[ctx.tx.processId].url, amount, recipientProcessId: sender})
.bimap(
Expand Down
3 changes: 3 additions & 0 deletions servers/mu/src/domain/lib/write-message-tx.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('writeMessageTxWith', () => {
}
},
RELAY_MAP: {
'ALLOWED_CURRENCIES': ["fromid"],
'mappedid1': { 'url': 'url1' },
'mappedid2': { 'url': 'url1' }
},
Expand All @@ -115,6 +116,7 @@ describe('writeMessageTxWith', () => {
url: 'https://foo.bar'
},
cachedMsg: {
fromProcessId: 'fromid',
msg: {
Tags: [{
name: 'Action',
Expand Down Expand Up @@ -156,6 +158,7 @@ describe('writeMessageTxWith', () => {
}
},
RELAY_MAP: {
'ALLOWED_CURRENCIES': ["ALL"],
'mappedid1': { 'url': 'url1' },
'mappedid2': { 'url': 'url1' }
},
Expand Down

0 comments on commit 7144de1

Please sign in to comment.