Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Conversation

@ShookLyngs
Copy link
Collaborator

@ShookLyngs ShookLyngs commented May 11, 2024

Changes

Checklist

@ShookLyngs ShookLyngs requested review from Flouse, ahonn and duanyytop May 11, 2024 02:04
@ShookLyngs ShookLyngs self-assigned this May 11, 2024
export function publicKeyToPayment(publicKey: string, addressType: AddressType, networkType: NetworkType) {
if (!publicKey) {
return void 0;
return undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be better to throw an exception than return undefined, so that the caller can realize the problem early.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this part of the code is not aligned with the the other functions in the address.ts. Some return undefined while some don't, I'll check them out and modify in another PR, if nessesary.

}

return void 0;
return undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

}
if (status !== 200) {
return void 0 as T;
return undefined as T;
Copy link
Collaborator

@duanyytop duanyytop May 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to throw an exception directly here

Copy link
Collaborator Author

@ShookLyngs ShookLyngs May 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is expected but the if statement is not clear, I'll update it in another PR.

const packedParams = params ? '?' + new URLSearchParams(pickBy(params, (val) => val !== undefined)).toString() : '';
const withOriginHeaders = this.origin ? { origin: this.origin } : void 0;
const withAuthHeaders = requireToken && this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
const withOriginHeaders = this.origin ? { origin: this.origin } : undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const withOriginHeaders = this.origin ? { origin: this.origin } : undefined;
const withOriginHeaders = { origin: this.origin };

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is expected, avoiding transparent { origin: undeinfed } for the readers

Copy link
Collaborator

@duanyytop duanyytop May 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the origin is undefined, the origin field will not appear in the headers for the real HTTP request and you can have a try.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I split them for better readability, although it may have failed to achieve its job. Another solution is that these properties can also be packed into the fetch call:

fetch('xxx', {
  headers: {
    authorization: requireToken && this.token ? `Bearer ${this.token}` : undefined,
    origin: this.origin,
    ...headers,
  },
})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

const tx = await this.service.getBtcTransaction(txId);
if (!tx) {
return void 0;
return undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to throw an exception directly here

Copy link
Collaborator Author

@ShookLyngs ShookLyngs May 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the reference of the function and it does look weird to throw afterward when nothing was found. I'll re-think about the signature of the function, and see if something were missing.

const vout = tx.vout[index];
if (!vout) {
return void 0;
return undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to throw an exception directly here

Base automatically changed from ref/sync-env-vars to develop May 11, 2024 07:12
@ahonn
Copy link
Contributor

ahonn commented May 11, 2024

This PR should be rebase from the develop branch to opt-out of the #164 code changes.

@ShookLyngs ShookLyngs force-pushed the style/remove-void-0 branch from a19e3a4 to e59322e Compare May 12, 2024 16:48
@ShookLyngs
Copy link
Collaborator Author

ShookLyngs commented May 12, 2024

This PR should be rebase from the develop branch to opt-out of the #164 code changes.

The commit message was altered when the #164 merged. It's now correctly rebased.

@ShookLyngs ShookLyngs requested a review from duanyytop May 13, 2024 07:07
@duanyytop
Copy link
Collaborator

After discussion, throwing errors instead of returning undefined will be updated in another PR.

@ShookLyngs ShookLyngs merged commit 5365ced into develop May 13, 2024
@duanyytop duanyytop deleted the style/remove-void-0 branch May 14, 2024 07:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants