-
Notifications
You must be signed in to change notification settings - Fork 89
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
662/mk/use open payments types #1024
Changes from 1 commit
c3ccd88
3415f5f
4693a79
c633b30
909462a
8feaacb
5300073
01a0ba0
36d8b8e
d04f994
379aee8
11fa542
27cfdde
4efddb3
dc051ec
0fddf9e
ad57048
d48dc0a
9302bad
5e5d4e8
25972d3
4800c80
cf95410
9a967f1
e5f3c03
5733224
28a34df
5e95486
b6d25c6
09a0c10
c079942
c55e586
fc311e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -84,7 +84,6 @@ export class IncomingPayment | |||||
} | ||||||
} | ||||||
|
||||||
public paymentPointer!: PaymentPointer | ||||||
public description?: string | ||||||
public expiresAt!: Date | ||||||
public state!: IncomingPaymentState | ||||||
|
@@ -131,8 +130,15 @@ export class IncomingPayment | |||||
this.receivedAmountValue = amount.value | ||||||
} | ||||||
|
||||||
public get url(): string { | ||||||
return `${this.paymentPointer.url}${IncomingPayment.urlPath}/${this.id}` | ||||||
public async getUrl(fetchedPaymentPointer?: PaymentPointer): Promise<string> { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if callers just assigned There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking a step back, if/when we change subresource urls to not include the payment pointer, we'll no longer need an async There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm hesitant to do that, since Maybe we can
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify, I'm only suggesting changing
Suggested change
and callers can optionally define |
||||||
const paymentPointer = | ||||||
fetchedPaymentPointer || (await this.getPaymentPointer()) | ||||||
|
||||||
return `${paymentPointer.url}${IncomingPayment.urlPath}/${this.id}` | ||||||
} | ||||||
|
||||||
public async getPaymentPointer(): Promise<PaymentPointer> { | ||||||
return this.paymentPointer ?? (await this.$relatedQuery('paymentPointer')) | ||||||
} | ||||||
|
||||||
public async onCredit({ | ||||||
|
@@ -243,22 +249,24 @@ export class IncomingPayment | |||||
return payment | ||||||
} | ||||||
|
||||||
public toOpenPaymentsType(): OpenPaymentsIncomingPayment | ||||||
public toOpenPaymentsType( | ||||||
public async toOpenPaymentsType(): Promise<OpenPaymentsIncomingPayment> | ||||||
public async toOpenPaymentsType( | ||||||
ilpStreamConnection: Connection | ||||||
): OpenPaymentsIncomingPaymentWithConnection | ||||||
public toOpenPaymentsType( | ||||||
): Promise<OpenPaymentsIncomingPaymentWithConnection> | ||||||
public async toOpenPaymentsType( | ||||||
ilpStreamConnection: string | ||||||
): OpenPaymentsIncomingPaymentWithConnectionUrl | ||||||
public toOpenPaymentsType( | ||||||
): Promise<OpenPaymentsIncomingPaymentWithConnectionUrl> | ||||||
public async toOpenPaymentsType( | ||||||
ilpStreamConnection?: Connection | string | ||||||
): | ||||||
): Promise< | ||||||
| OpenPaymentsIncomingPayment | ||||||
| OpenPaymentsIncomingPaymentWithConnection | ||||||
| OpenPaymentsIncomingPaymentWithConnectionUrl { | ||||||
| OpenPaymentsIncomingPaymentWithConnectionUrl | ||||||
> { | ||||||
const paymentPointer = await this.getPaymentPointer() | ||||||
const baseIncomingPayment: OpenPaymentsIncomingPayment = { | ||||||
id: this.url, | ||||||
paymentPointer: this.paymentPointer.url, | ||||||
id: await this.getUrl(paymentPointer), | ||||||
paymentPointer: paymentPointer.url, | ||||||
incomingAmount: this.incomingAmount | ||||||
? serializeAmount(this.incomingAmount) | ||||||
: undefined, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,9 @@ export async function getPaymentPointer( | |
interface ListSubresourceOptions<M extends PaymentPointerSubresource> { | ||
ctx: ListContext | ||
getPaymentPointerPage: PaymentPointerSubresourceService<M>['getPaymentPointerPage'] | ||
toBody: (model: M) => Record<string, unknown> | ||
toBody: | ||
| ((model: M) => Record<string, unknown>) | ||
| ((model: M) => Promise<Record<string, unknown>>) | ||
} | ||
|
||
export const listSubresource = async <M extends PaymentPointerSubresource>({ | ||
|
@@ -66,9 +68,9 @@ export const listSubresource = async <M extends PaymentPointerSubresource>({ | |
) | ||
const result = { | ||
pagination: pageInfo, | ||
result: page.map((item: M) => { | ||
result: page.map(async (item: M) => { | ||
item.paymentPointer = ctx.paymentPointer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are fetching paymentPointer on the fly (whenever it's missing), this line isn't necessary |
||
return toBody(item) | ||
return await toBody(item) | ||
}) | ||
} | ||
ctx.body = result | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -80,7 +80,7 @@ async function createQuote( | |||||
} | ||||||
|
||||||
ctx.status = 201 | ||||||
ctx.body = quoteToBody(quoteOrErr) | ||||||
ctx.body = await quoteToBody(quoteOrErr) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Remove |
||||||
} catch (err) { | ||||||
if (isQuoteError(err)) { | ||||||
return ctx.throw(errorToCode[err], errorToMessage[err]) | ||||||
|
@@ -90,6 +90,6 @@ async function createQuote( | |||||
} | ||||||
} | ||||||
|
||||||
function quoteToBody(quote: Quote): OpenPaymentsQuote { | ||||||
async function quoteToBody(quote: Quote): Promise<OpenPaymentsQuote> { | ||||||
return quote.toOpenPaymentsType() | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no non-null assertion since we can start removing
withGraphFetched('paymentPointer')
from the DB calls