Conversation
…ng fetched multiple times.
| <key>Description</key> | ||
| <dict> | ||
| <key>StringFormat</key> | ||
| <string>Registered %@</string> |
There was a problem hiding this comment.
What do you guys think of this approach? Maintaining a list of string formats per contract/methodId so we can display the tx input in a descriptive way, instead of dumping the method name and its arguments? But it's something we'd have to maintain over time...
There was a problem hiding this comment.
I think maintaining a list is a good idea. While it involves more upfront work, and the ongoing maintenance cost, it's the best approach we have so far to provide really clear, user-friendly descriptions of transactions.
One question: why a plist? Would it not be better to put this in Swift directly, perhaps a map from address+method to a callback? This way, we can not only return text, but also other pieces of UI (logos, links, perhaps even in-wallet actions?)
There was a problem hiding this comment.
In addition to our discussions, this approach is still a bit limited as it assumes that the parameter value’s string representation can be readily displayed. However, in some cases we will need to do some further formatting, e.g. when the input parameter is a timestamp, we would like to format it in a readable way. One way we could handle this is to add an additional type argument which tells the client how to format the value. wdyt?
There was a problem hiding this comment.
Yea, I agree. What about using String(format:_:), or another string formatting API, or a library? https://riptutorial.com/swift/example/6342/formatting-strings
There was a problem hiding this comment.
Right! So in the current PR String(format:arguments:) is used (see TransactionInputParser). So we should be able to handle different format specifiers. But if we wanted to do date formatting for example then string formats wouldn't be sufficient anymore.
There are also a couple of other things to consider:
- The format specifier used in the string format has to match the type of the decoded input param.
- The list of arguments provided in the plist/json to be in the right order. Also each argument in the plist/json needs to match the param name of the decoded input.
It's easy for errors to creep in here. When the list contains errors in the string format or the supplied argument names then it will be difficult to catch. We will need to think about how we can add further validation perhaps, and/or how to properly test updates in the string format list.
| } | ||
| } | ||
|
|
||
| private func convertRawValueToString(inputData: InputData) -> String? { |
There was a problem hiding this comment.
Just simple conversion to string values right now so we can display it on the tx history detail page for demo purposes.
| <key>Description</key> | ||
| <dict> | ||
| <key>StringFormat</key> | ||
| <string>Registered %@</string> |
There was a problem hiding this comment.
In addition to our discussions, this approach is still a bit limited as it assumes that the parameter value’s string representation can be readily displayed. However, in some cases we will need to do some further formatting, e.g. when the input parameter is a timestamp, we would like to format it in a readable way. One way we could handle this is to add an additional type argument which tells the client how to format the value. wdyt?
|
This is an interesting problem :) It might make sense to add a field with a format description or maybe even a regex for odd cases. However, timestamps are especially tricky and I don't know if a regex is the best approach here. I think it will be a two step process:
Step 2 is relatively straightforward. DateFormatter has been around for a long time, and Swift 5.5 has a new date formatter system I haven't tried yet but looks promising. Step 1 is a little bit more complicated because there are just so many different ways to store dates in a string (and they claim to be "standard"). I wonder if we could add a field date parameters in the plist that stores the date format that's easy to parse by DateFormatter or the new Swift formatting methods. Maybe the field should say something like |
Tx List Screenshot:

Tx Detail Screenshot:

This PR implements transaction input parsing. It parses the tx input in order to retrieve the method that was invoked along with the call arguments.
The approach is as follows: