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

Avoid changing global axios.defaults.transformResponse #47

Merged
merged 2 commits into from
Aug 23, 2021

Conversation

pctj101
Copy link
Contributor

@pctj101 pctj101 commented Aug 4, 2021

What do you think about isolating the axios config to the local file, rather than changing axios for the global scope?

For example, this is one case of the axios global config change introduced by erdjs that conflicts with arweave.
#46

It could make it easier to integrate elrond/erdjs with more dapps with fewer chances of conflict.

@@ -24,10 +24,16 @@ export class ApiProvider implements IApiProvider {
*/
constructor(url: string, config?: AxiosRequestConfig) {
this.url = url;
// See: https://github.com/axios/axios/issues/983
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe tie the comment to the transformResponse property?

@@ -26,8 +26,14 @@ export class ProxyProvider implements IProvider {
*/
constructor(url: string, config?: AxiosRequestConfig) {
this.url = url;
// See: https://github.com/axios/axios/issues/983
this.config = config || {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we should use Object.assign or something to merge the provided config and the defaults so that one default won't get lost when a config is passed as a parameter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ping @pctj101 - Do you think you can implement the requested changes? Or should we do it - there's no problem either way.
Then we can merge this PR :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh hi! I was caught up in a few things but I can get to it later today :) Thanks for saying hi!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pushed up a change, but definitely take a look at the data type comment below in case you have any insight.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks a lot!

}
// See: https://github.com/axios/axios/issues/983 regarding transformResponse
transformResponse: [
function(data: any) {
Copy link
Contributor Author

@pctj101 pctj101 Aug 19, 2021

Choose a reason for hiding this comment

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

Typescript complained about a lack of type for data, so I put "any"

It seems in most cases it's a string, but looking at axios itself, it seems there are times that even axios needs to fall back when data is not a string.

https://github.com/axios/axios/blob/master/lib/defaults.js#L72

At least for elrond cases, the config scoped for the purposes of elrond APIs seems to be able to assume a string.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey there. It's ok for now to leave it with any. Regardless of what axios provides in transformResponse as data, I think we should make sure ourselves it's a string before passing it to JSONbig.parse. But this is out of the scope of this PR, I'll make sure we update the error handling here in the case data is not a string.

Copy link
Contributor

Choose a reason for hiding this comment

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

@pctj101 I changed the base to development. Can you please resolve the two conflicts? They're small, you should just keep your changes :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ccorcoveanu Hello again! Appreciate the feedback. Merged against development and matched up the indent.

ccorcoveanu
ccorcoveanu previously approved these changes Aug 19, 2021
@ccorcoveanu ccorcoveanu changed the base branch from main to development August 19, 2021 08:32
@ccorcoveanu ccorcoveanu dismissed their stale review August 19, 2021 08:32

The base branch was changed.

@ccorcoveanu ccorcoveanu merged commit 1429591 into multiversx:development Aug 23, 2021
danielailie pushed a commit that referenced this pull request Oct 2, 2024
Accept "Uint8Array", in addition to "Buffer" (on the main flows: sign, verify)
danielailie pushed a commit that referenced this pull request Oct 2, 2024
Accept "Uint8Array", in addition to "Buffer" (on the main flows: sign, verify)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants