Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit fb75280

Browse files
committed
Fix cryptolisting price calculation for ETH payments
The crypto listing total calculation code was not adjusting for the payment coin's level of precision and thus was returning only a few digits when paying with eth instead of the full precision. closes #1835
1 parent 1851ea1 commit fb75280

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

core/order.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,11 +1344,16 @@ func (n *OpenBazaarNode) getMarketPriceInSatoshis(pricingCurrency, currencyCode
13441344
if err != nil {
13451345
return big.NewInt(0), err
13461346
}
1347-
r, _ := big.NewFloat(rate).Int(nil)
1348-
if r.Int64() == 0 {
1349-
return big.NewInt(0), errors.New("invalid rate of zero value")
1347+
1348+
cv, err := repo.NewCurrencyValue(amount.String(), currencyDef)
1349+
if err != nil {
1350+
return nil, err
1351+
}
1352+
newCV, _, err := cv.ConvertTo(pricingDef, 1/rate)
1353+
if err != nil {
1354+
return nil, err
13501355
}
1351-
return new(big.Int).Div(amount, r), nil
1356+
return newCV.Amount, nil
13521357
}
13531358

13541359
func verifySignaturesOnOrder(contract *pb.RicardianContract) error {

0 commit comments

Comments
 (0)