-
Notifications
You must be signed in to change notification settings - Fork 50
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
Conversation
…w message parsing
if (typeof msg === 'string') { | ||
return msg | ||
} | ||
|
||
if (msg.length > 1) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
}
apps/wallet-mobile/src/features/ReviewTx/common/hooks/useFormattedMetadata.tsx
Outdated
Show resolved
Hide resolved
} catch { | ||
return message | ||
} | ||
const parseMsg = (msg: Array<string> | string): string => { |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point
There was a problem hiding this comment.
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)
Description / Change(s) / Related issue(s)
Fix address path for message signing and TX review message parsing
Ticket
YV-245