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

feat: add estimatedExchangeRate property to quote response #498

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/mighty-pans-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@interledger/open-payments': patch
---

Add `estimatedExchangeRate` property to `Quote`.
4 changes: 4 additions & 0 deletions openapi/resource-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,10 @@ components:
description: "The total amount that should be deducted from the sender's account when the corresponding outgoing payment has been paid. "
method:
$ref: '#/components/schemas/payment-method'
estimatedExchangeRate:
type: number
description: 'Estimated probed exchange rate over the path (ILP specific).'
readOnly: true
expiresAt:
type: string
description: The date and time when the calculated `debitAmount` is no longer valid.
Expand Down
38 changes: 38 additions & 0 deletions packages/open-payments/src/client/quote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ describe('quote', (): void => {

describe('getQuote', (): void => {
test('returns the quote if it passes open api validation', async (): Promise<void> => {
const scope = nock(baseUrl).get(`/quotes/${quote.id}`).reply(200, quote)
const result = await getQuote(
deps,
{
url: `${baseUrl}/quotes/${quote.id}`,
accessToken
},
openApiValidators.successfulValidator
)
expect(result).toEqual(quote)
expect(result.estimatedExchangeRate).toBeUndefined()
scope.done()
})

test('returns the quote with the estimated exchange rate if it passes open api validation', async (): Promise<void> => {
const quote = mockQuote({
estimatedExchangeRate: 120
})
const scope = nock(baseUrl).get(`/quotes/${quote.id}`).reply(200, quote)
const result = await getQuote(
deps,
Expand Down Expand Up @@ -79,6 +97,7 @@ describe('quote', (): void => {
{ receiver: quote.receiver, method: 'ilp', walletAddress }
)
expect(result).toEqual(quote)
expect(result.estimatedExchangeRate).toBeUndefined()
scope.done()
})

Expand All @@ -97,6 +116,25 @@ describe('quote', (): void => {
).rejects.toThrowError()
scope.done()
})

test('returns estimated exchange rate if amount can not be sent over the path', async (): Promise<void> => {
const quote = mockQuote({
receiveAmount: { value: '0', assetCode: 'ZAR', assetScale: 2 },
estimatedExchangeRate: 120
})
const scope = nock(baseUrl).post(`/quotes`).reply(200, quote)
const result = await createQuote(
deps,
{
url: baseUrl,
accessToken
},
openApiValidators.successfulValidator,
{ receiver: quote.receiver, method: 'ilp', walletAddress }
)
expect(result).toEqual(quote)
scope.done()
})
})

describe('routes', (): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ export interface components {
/** @description The total amount that should be deducted from the sender's account when the corresponding outgoing payment has been paid. */
debitAmount: external["schemas.yaml"]["components"]["schemas"]["amount"];
method: components["schemas"]["payment-method"];
/** @description Estimated probed exchange rate over the path (ILP specific). */
estimatedExchangeRate?: number;
/** @description The date and time when the calculated `debitAmount` is no longer valid. */
expiresAt?: string;
/**
Expand Down
Loading