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

Commit 6b229b9

Browse files
authored
Merge pull request #1849 from OpenBazaar/cryptoethpayment
(#1835) Fix cryptolisting price calculation for ETH payments
2 parents 4e7a7cf + fb75280 commit 6b229b9

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)