In the gateway, we use five different ways to represent numbers. As numbers, as strings, and BN's, as BigNumbers etc. Although things work, it makes maintaining and understanding the gateway difficult.
Here is an example of the complexity:
Values entered by the user are typically floats, but values returned from contracts are BigInts, and those in turn are handled either as strings or as BigNumbers. The difficulty lies in making sure that user inputs (e.g. 22.0) and precise values from the contracts do not clash. For example, when a user clicks USE ALL, they expect their wallet balance afterwards to be precisely zero, and therefore, the values provided to the contracts need to be uncorrupted BigInts. In parts of the code, the approach that is being used is to have two sets of numbers, for example, value (typeof = float) and value_Wei_String (typeof = string). For USE ALL operations, the system must only ever use value_Wei_String as inputs. The code above accomplishes this by maintaining value and value_Wei_String.
By contrast, here is an example of a bad way to do this:
Where is the problem? handleStakeValue takes value inputs, and converts those into value_Wei_String. That's wrong, since the actual value of the value_Wei_String will get corrupted by value_Wei_String->value->maxValue->value->value_Wei_String.
ToDo - Develop a better way to handle values overall, and then, implement and test that system across the gateway.
In the gateway, we use five different ways to represent numbers. As numbers, as strings, and BN's, as BigNumbers etc. Although things work, it makes maintaining and understanding the gateway difficult.
Here is an example of the complexity:
Values entered by the user are typically floats, but values returned from contracts are BigInts, and those in turn are handled either as strings or as BigNumbers. The difficulty lies in making sure that user inputs (e.g. 22.0) and precise values from the contracts do not clash. For example, when a user clicks
USE ALL
, they expect their wallet balance afterwards to be precisely zero, and therefore, the values provided to the contracts need to be uncorrupted BigInts. In parts of the code, the approach that is being used is to have two sets of numbers, for example,value
(typeof = float) andvalue_Wei_String
(typeof = string). For USE ALL operations, the system must only ever usevalue_Wei_String
as inputs. The code above accomplishes this by maintainingvalue
andvalue_Wei_String
.By contrast, here is an example of a bad way to do this:
Where is the problem?
handleStakeValue
takesvalue
inputs, and converts those intovalue_Wei_String
. That's wrong, since the actual value of thevalue_Wei_String
will get corrupted by value_Wei_String->value->maxValue->value->value_Wei_String.ToDo - Develop a better way to handle values overall, and then, implement and test that system across the gateway.