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(wallet-mobile): Fix address path for message signing and TX review message parsing #3843

Merged
merged 6 commits into from
Feb 21, 2025

Conversation

michaeljscript
Copy link
Collaborator

@michaeljscript michaeljscript commented Feb 21, 2025

Description / Change(s) / Related issue(s)

Fix address path for message signing and TX review message parsing

Ticket

YV-245

@github-actions github-actions bot added the fix label Feb 21, 2025
@michaeljscript michaeljscript self-assigned this Feb 21, 2025
@michaeljscript michaeljscript added this to the 5.3.0 milestone Feb 21, 2025
if (typeof msg === 'string') {
return msg
}

if (msg.length > 1) {
Copy link
Member

Choose a reason for hiding this comment

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

I think is misleading, maybe make it more declarative, -> if Array.isArray ..., first, and then fall back to string, cuz [].join still works, unless is needed to check if it is an array and there is at least 1 element.

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, it seems that there are different rules when the length is 1 and when the length is > 1. I'll do a small refactor and ping you to check again if it looks better. It may be good to hear @banklesss thoughts

Copy link
Member

Choose a reason for hiding this comment

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

maybe something like const string2sign = Array.isArray(msg) ? msg.join() : msg, states clear that signing expects a string only

Copy link
Collaborator Author

@michaeljscript michaeljscript Feb 21, 2025

Choose a reason for hiding this comment

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

Note this is not used for signing, just displaying on the TX review screen

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've changed it to the following

const messageToParse = Array.isArray(msg) ? msg.join('') : msg

  try {
    return JSON.parse(messageToParse)
  } catch {
    return messageToParse
  }

} catch {
return message
}
const parseMsg = (msg: Array<string> | string): string => {
Copy link
Member

Choose a reason for hiding this comment

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

@michaeljscript -> I know what is bugging me, the return type can be whatever, --> JSON.parse('1') = number not string, maybe parse, and then stringify after? :dunno:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah good point

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

const parsed = JSON.parse(messageToParse)
if (isString(parsed)) return parsed
return JSON.stringify(parsed)

@stackchain stackchain merged commit 543d9f0 into develop Feb 21, 2025
1 check passed
@stackchain stackchain deleted the fix/wallet-signing branch February 21, 2025 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants