Skip to content

Commit

Permalink
feat(backend): add quotes route to exceptions in wallet address middl…
Browse files Browse the repository at this point in the history
…eware (#2108)
  • Loading branch information
njlie authored Oct 24, 2023
1 parent f1af4f8 commit fdcb251
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/backend/src/open_payments/quote/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ describe('Quote Routes', (): void => {

test('returns error on invalid debitAmount asset', async (): Promise<void> => {
options = {
walletAddress: walletAddress.url,
receiver,
debitAmount: {
...debitAmount,
Expand Down Expand Up @@ -172,6 +173,7 @@ describe('Quote Routes', (): void => {
'$description',
async ({ debitAmount, receiveAmount }): Promise<void> => {
options = {
walletAddress: walletAddress.url,
receiver,
method: 'ilp'
}
Expand Down Expand Up @@ -242,6 +244,7 @@ describe('Quote Routes', (): void => {

test('receiver.incomingAmount', async (): Promise<void> => {
options = {
walletAddress: walletAddress.url,
receiver,
method: 'ilp'
}
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/open_payments/quote/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ async function getQuote(
}

interface CreateBodyBase {
walletAddress: string
receiver: string
method: 'ilp'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { AppContext } from '../../app'
import { CreateBody as IncomingCreateBody } from '../../open_payments/payment/incoming/routes'
import { CreateBody as OutgoingCreateBody } from '../../open_payments/payment/outgoing/routes'
import { CreateBody as QuoteCreateBody } from '../../open_payments/quote/routes'

type CreateBody = IncomingCreateBody | OutgoingCreateBody
type CreateBody = IncomingCreateBody | OutgoingCreateBody | QuoteCreateBody

export function createWalletAddressMiddleware() {
return async (
Expand All @@ -11,7 +12,8 @@ export function createWalletAddressMiddleware() {
): Promise<void> => {
if (
ctx.path === '/incoming-payments' ||
ctx.path === '/outgoing-payments'
ctx.path === '/outgoing-payments' ||
ctx.path === '/quotes'
) {
if (ctx.method === 'GET') {
ctx.walletAddressUrl = ctx.query['wallet-address'] as string
Expand All @@ -23,6 +25,7 @@ export function createWalletAddressMiddleware() {
} else {
ctx.walletAddressUrl = `https://${ctx.request.host}/${ctx.params.walletAddressPath}`
}

const config = await ctx.container.use('config')
if (ctx.walletAddressUrl !== config.walletAddressUrl) {
const walletAddressService = await ctx.container.use(
Expand Down

0 comments on commit fdcb251

Please sign in to comment.