-
Notifications
You must be signed in to change notification settings - Fork 90
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
fix(backend): allow admin api to query all receivers and move checks #3314
base: main
Are you sure you want to change the base?
fix(backend): allow admin api to query all receivers and move checks #3314
Conversation
✅ Deploy Preview for brilliant-pasca-3e80ec canceled.
|
tests tbd after review |
@@ -120,4 +108,30 @@ export class Receiver { | |||
requestCounter: Counter.from(0) as Counter | |||
} | |||
} | |||
|
|||
public static isInvalidExpiredOrCompleted( |
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.
Does this need to be a static method? Or can we just make it a regular method, and use this
to refer to the receiver instead of passing it in? This allows us to not import the Receiver
model across our different services and leverages the receiver instance we already have.
Then instead of handling undefined
in this method we check where this is called like:
So this:
if (!receiver || receiver.isInvalidExpiredOrCompleted()) {
throw OutgoingPaymentError.InvalidQuote
}
Instead of
if (Receiver.isInvalidExpiredOrCompleted(receiver)) {
throw OutgoingPaymentError.InvalidQuote
}
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.
It does not, I chose static for simplicity only. Changed to non-static method.
if (!incomingPayment.methods.length) { | ||
// throw new Error('Missing payment method(s) on incoming payment') | ||
return true | ||
} |
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.
We can probably remove this payment method check. Its not going to do anything because the Receiver
constructor will error if it's empty. It looks for ilp method then throws if it cant find it.
I am considering if it should be returned to the constructor but it seems kind of redundant in the first place. With or without a check for this, if method is empty, it will error as described here (missing ilp payment method). I guess the method.length
check was just slightly more informative. I think just remove it here.
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.
moved to constructor for now because it makes more sense since there's already a check there and ILP method is hard-coupled to the Receiver via ilpAddress
property.
Checked if this will affect querying the receiver via Admin API and it doesn't.
|
||
public static isInvalidExpiredOrCompleted( | ||
receiver: Receiver | undefined | ||
): receiver is undefined { |
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.
Can you speak more to this return type? I think maybe it should just be boolean
instead? Perhaps it was working differently with the pattern of throwing errors but I don't think its really doing anything here. Nor could TS really know if its undefined or not.
This is what I see when using it (no effect on the receiver passed in).
const maybeReceiver = {} as Receiver | undefined
const r = Receiver.isInvalidExpiredOrCompleted(maybeReceiver)
r // type is boolean
maybeReceiver //type is still Receiver | undefined
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.
first time around I did it, function signature response was boolean
public static isActive(receiver: Receiver | undefined): boolean {
the issue was that I had to double check for type:
but if we do the non-static method that you suggested, then we won't have this problem because we will check for type before using the method
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.
when the signature response is receiver is Receiver
and you have an if with a return or throw just like above, then typescript will know that the receiver below the if will be just of type Receiver (instead of Receiver | undefined)
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.
// function will return boolean, but typescript knows what to do with it
function isActive(r: Receiver | undefined): receiver is Receiver
const maybeReceiver = {} as Receiver | undefined
const r = Receiver.isActive(maybeReceiver)
r // type is boolean
maybeReceiver //type is still Receiver | undefined
if (!r) {
return;
}
maybeReceiver //type is Receiver only
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.
That makes sense, I see how its working now.
@@ -33,9 +33,6 @@ function getStreamCredentials( | |||
deps: ServiceDependencies, | |||
payment: IncomingPayment | |||
): IlpStreamCredentials | undefined { | |||
if (payment.isExpiredOrComplete()) { |
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.
IncomingPayment.isExpiredOrComplete()
isn't used anywhere else in the code with this deletion - perhaps it can be cleaned up?
} | ||
const incomingPayment = receiver.incomingPayment | ||
if (incomingPayment.completed) { | ||
// throw new Error('Cannot create receiver from completed incoming payment') |
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.
nit: clean up comments
Changes proposed in this pull request
Resolver.isInvalidExpiredOrCompleted
Context
fixes #3253
Checklist
fixes #number
user-docs
label (if necessary)