diba-io / bitmask-core

Core functionality for the BitMask wallet
https://bitmask.app
Other
95 stars 21 forks source link

Support to Fractions #396

Closed crisdut closed 1 year ago

crisdut commented 1 year ago

Description

This PR add support to fractions in issuer, create invoice and transfers (include swaps) operations.

Changes (!!Important!!)

I was need change some pre-reqs of the issue #363 for feature work correctly. In my tests, I identify some problems with we send only whole and fraction. See bellow:

  1. Conversions: Each language (Rust, TS and JS) have different ways to convert and handle numbers and this leaves room for countless errors. To avoid wrong conversions, I decided change the type of contract amount from number to string and handle in BMC. The BME send the follow representations of the fractional number: 2., 2.0, 2.0, 2.0000001, 2.5, etc..
  2. Precisions: Another problem is contract precisions. To avoid user send wrong values in invoice, I change the invoice amount to string too. Also, now the receiver needs already imported contract, because we checked if user send a correct precision number. Also, I create the method called get_simple_contract in web.rs to return the contract precision data.

Closes #363