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

changed the href to fix the problem #856

Merged
merged 8 commits into from
Oct 23, 2023

Conversation

sohammk08
Copy link
Contributor

@sohammk08 sohammk08 commented Oct 9, 2023

High Level Overview of Change

Slightly changed the href in the DomainLink.tsx file. Addresses issue #714

Context of Change

Some accounts such as the issuers of NFTs put fully formatted urls in the domain field. Since "https://" is prepended to the value of that field, an invalid URI is created. The change adds "https://" only if a protocol is not detected.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

TypeScript/Hooks Update

  • Updated files to React Hooks
  • Updated files to TypeScript

Before / After

Before: "https://" was prepended to the value of that field, creating a invalid URL
After: Now, "https://" is added only if a protocol is not detected.

Test Plan

No test plan in practice for the current change.

Note

This is the example given in the issue: https://livenet.xrpl.org/accounts/r481fwr9G6GqJsnDTRanb9wicGjFf3rfgp/transactions

For some reason, whenever I click the DOMAIN on the accounts page(of the example), it leads to:

http://https//marketplace-api.onxrp.com/api/metadata/

When it should lead to this, instead:

https://marketplace-api.onxrp.com/api/metadata/

I suspect that there might be a problem with the data being passed to the DomainLink component. I have not been able to pinpoint it though.

Further feedback is much appreciated.

Thanks you :)

@sohammk08 sohammk08 marked this pull request as draft October 9, 2023 11:11
@sohammk08 sohammk08 changed the title slightly changed the href to fix the problem changed the href to fix the problem Oct 11, 2023
Added a test in DomainLink.test.ts that checks if the domain being provided is HEX-encoded
@sohammk08
Copy link
Contributor Author

I ran it on my machine and it passes all the tests without raising any additional issues. Please take a look.

@sohammk08 sohammk08 marked this pull request as ready for review October 15, 2023 18:55
updates the DomainLink component to handle domain protocols more effectively. It includes changes to check for the presence of protocols (http:// or https://), improving the handling of decoded domains, and ensuring the proper construction of href attributes.
…nent

refactored the DomainLink component by enhancing the protocol detection logic, now using a pre-defined regex 'protocolRegex' for improved efficiency
Comment on lines 42 to 49
const wrapper = mount(
<DomainLink decode domain="68747470733A2F2F6578616D706C652E636F6D" />,
)
expect(wrapper.find('a').props().className).toEqual('domain')
expect(wrapper.find('a').text()).toEqual('https://example.com')
expect(wrapper.find('a').props().href).toEqual('https://example.com')
wrapper.unmount()
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a bit more understandable:

Suggested change
const wrapper = mount(
<DomainLink decode domain="68747470733A2F2F6578616D706C652E636F6D" />,
)
expect(wrapper.find('a').props().className).toEqual('domain')
expect(wrapper.find('a').text()).toEqual('https://example.com')
expect(wrapper.find('a').props().href).toEqual('https://example.com')
wrapper.unmount()
})
const url = 'https://example.com'
const urlHex = encodeHex(url)
const wrapper = mount(
<DomainLink decode domain={urlHex} />,
)
expect(wrapper.find('a').props().className).toEqual('domain')
expect(wrapper.find('a').text()).toEqual(url)
expect(wrapper.find('a').props().href).toEqual(url)
wrapper.unmount()
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As for the additional test that is created in the DomainLink.test.tsx, I just followed the format of the previous tests in the same test file. If only this test is changed, the file will be non-uniform. If you still want to change it the way you mentioned above, let me know.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a good point. I'd still change this test - readability >> consistency for minor things like this. If I were writing this PR I'd modify all the old tests as well, but you don't have to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it for better readability: b8fc786

@ckniffen ckniffen merged commit 47836ea into ripple:staging Oct 23, 2023
4 checks passed
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.

None yet

3 participants