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

fix: Rectified the incorrect tuple value #1166

Merged
merged 6 commits into from
Sep 20, 2023

Conversation

shamim-io
Copy link
Contributor

@shamim-io shamim-io commented Jun 12, 2023

closes #1156

Closes Incorrect display of optional in tuple result #1156

Fixes issue: Incorrect display of optional in tuple result

Feature details
Rectified the incorrect tuple value

Feature image
Screenshot 2023-06-13 at 2 52 41 AM

@vercel
Copy link

vercel bot commented Jun 12, 2023

@shamim-io is attempting to deploy a commit to the Hiro Systems Team on Vercel.

A member of the Team first needs to authorize it.

const value = arg.repr.replace('u', '');
if (arg.name.includes('ustx')) {
const value = arg?.repr?.replace('u', '');
if (arg?.name?.includes('ustx')) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest we remove the optional operator ? whenever possible. It looks like it used to expect arg to always exist.


const getReprValue = (item: any) => {
let reprValue = item?.value ?? 'none';
if (item?.type?.includes('list')) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same for this one

@He1DAr
Copy link
Collaborator

He1DAr commented Jun 13, 2023

Thank you for the PR @shamim-io! Left a few comments, please let me know if you have any questions.

@shamim-io
Copy link
Contributor Author

@He1DAr Can you please provide me a new tx link. The link that was provide to me earlier seems doesn't exist anymore. This was the link provided previously: https://explorer.hiro.so/txid/0x5644ab5008b78ada724946693bae8b64b221f84ed3234152e1553a1f978e8d3a?chain=testnet

@He1DAr
Copy link
Collaborator

He1DAr commented Jun 16, 2023

@shamim-io
Copy link
Contributor Author

@He1DAr I have updated the PR. Please check!

Copy link
Collaborator

@He1DAr He1DAr left a comment

Choose a reason for hiding this comment

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

Awesome work @shamim-io! Left a few comments.

if (item.type.includes('list')) {
reprValue = item.value.map((listEntry: any) => listEntry.value).join(', ');
}
return typeof reprValue === 'object' ? JSON.stringify(reprValue) : reprValue.toString();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please try to avoid calling toString for the list case as it's already a string. A similar implementation like existing one should do the trick.

@@ -15,6 +15,15 @@ export const FunctionSummaryResult = ({ result, txStatus }: FunctionSummaryResul
if (!result) return null;
const { success, type, value } = cvToJSON(hexToCV(result.hex));
const hasType = !type?.includes('UnknownType');

const getReprValue = (item: any) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add typing to function argument and unit tests.

@@ -77,7 +77,16 @@ const TupleResult = ({ tuple, isPoxAddr, btc }: any) => {
);
};

const getValue = (arg: { name: string; type: any; repr: any; value: any }, btc: null | string) => {
const isJSONString = (str: string) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest we move this to utility file and add a unit test.

}
};

const getValue = (arg: any, btc: null | string) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add typing to function argument.

}
};

const getValue = (arg: any, btc: null | string) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add unit tests to getValue function that cover both cases (arg.repr is/isn't json).

@vercel
Copy link

vercel bot commented Jun 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hiro-explorer 🔄 Building (Inspect) Jun 26, 2023 1:37pm

@shamim-io
Copy link
Contributor Author

@He1DAr I have updated the PR by adding typings and test cases wherever possible. However, there are components that still lack test cases. In those cases, I have refrained from writing a test case for a small function to avoid duplicating efforts. Instead, we need to create a test file for the entire component.

if (!result) return null;
const { success, type, value } = cvToJSON(hexToCV(result.hex));
const hasType = !type?.includes('UnknownType');

const getReprValue = ({ type, value }: ReprValueProps) => {
let reprValue = value ?? 'none';
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would add .toString(); to the value here to match the old code. This part is pretty sensitive to changes.

if (!result) return null;
const { success, type, value } = cvToJSON(hexToCV(result.hex));
const hasType = !type?.includes('UnknownType');

const getReprValue = ({ type, value }: ReprValueProps) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this function can be defined outside the component.

@@ -0,0 +1,45 @@
import { getValue } from './value';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for adding tests!

const getReprValue = ({ type, value }: ReprValueProps) => {
let reprValue = value ?? 'none';
if (type.includes('list') && Array.isArray(value)) {
reprValue = value.map((listEntry: any) => listEntry.value).join(', ');
Copy link
Collaborator

Choose a reason for hiding this comment

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

would be great if we eliminate this remaining any

@He1DAr
Copy link
Collaborator

He1DAr commented Jun 28, 2023

@He1DAr I have updated the PR by adding typings and test cases wherever possible. However, there are components that still lack test cases. In those cases, I have refrained from writing a test case for a small function to avoid duplicating efforts. Instead, we need to create a test file for the entire component.

Sounds good! Thank you for adding tests. I left a few tiny comments. Great work @shamim-io!

@He1DAr He1DAr merged commit fe80f8b into hirosystems:main Sep 20, 2023
3 of 5 checks passed
@blockstack-devops
Copy link

🎉 This PR is included in version 1.123.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Incorrect display of optional in tuple result
3 participants