Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Feb 12, 2021
1 parent 4ce0a95 commit 0756b0b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
20 changes: 10 additions & 10 deletions client/asset/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,26 +697,26 @@ func (btc *ExchangeWallet) feeRateWithFallback(confTarget uint64) uint64 {
// associated with nfo.MaxFeeRate. For quote assets, the caller will have to
// calculate lotSize based on a rate conversion from the base asset's lot size.
func (btc *ExchangeWallet) MaxOrder(lotSize uint64, nfo *dex.Asset) (*asset.SwapEstimate, error) {
_, _, _, maxEst, err := btc.maxOrder(lotSize, nfo)
_, _, maxEst, err := btc.maxOrder(lotSize, nfo)
return maxEst, err
}

// maxOrder gets the estimate for MaxOrder, and also returns the
// []*compositeUTXO to be used for further order estimation without additional
// calls to listunspent.
func (btc *ExchangeWallet) maxOrder(lotSize uint64, nfo *dex.Asset) (utxos []*compositeUTXO, lots, feeRate uint64, est *asset.SwapEstimate, err error) {
func (btc *ExchangeWallet) maxOrder(lotSize uint64, nfo *dex.Asset) (utxos []*compositeUTXO, feeRate uint64, est *asset.SwapEstimate, err error) {
networkFeeRate, err := btc.feeRate(1)
if err != nil {
return nil, 0, 0, nil, fmt.Errorf("error getting network fee estimate: %w", err)
return nil, 0, nil, fmt.Errorf("error getting network fee estimate: %w", err)
}
btc.fundingMtx.RLock()
utxos, _, avail, err := btc.spendableUTXOs(0)
btc.fundingMtx.RUnlock()
if err != nil {
return nil, 0, 0, nil, fmt.Errorf("error parsing unspent outputs: %w", err)
return nil, 0, nil, fmt.Errorf("error parsing unspent outputs: %w", err)
}
// Start by attempting max lots with no fees.
lots = avail / lotSize
lots := avail / lotSize
for lots > 0 {
est, _, err := btc.estimateSwap(lots, lotSize, networkFeeRate, utxos, nfo, btc.useSplitTx)
// The only failure mode of estimateSwap -> btc.fund is when there is
Expand All @@ -726,9 +726,9 @@ func (btc *ExchangeWallet) maxOrder(lotSize uint64, nfo *dex.Asset) (utxos []*co
lots--
continue
}
return utxos, lots, networkFeeRate, est, nil
return utxos, networkFeeRate, est, nil
}
return utxos, 0, networkFeeRate, &asset.SwapEstimate{}, nil
return utxos, networkFeeRate, &asset.SwapEstimate{}, nil
}

// PreSwap get order estimates based on the available funds and the wallet
Expand All @@ -741,12 +741,12 @@ func (btc *ExchangeWallet) PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, erro
// The utxo set is only used once right now, but when order-time options are
// implemented, the utxos will be used to calculate option availability and
// fees.
utxos, maxLots, feeRate, _, err := btc.maxOrder(req.LotSize, req.AssetConfig)
utxos, feeRate, maxEst, err := btc.maxOrder(req.LotSize, req.AssetConfig)
if err != nil {
return nil, err
}
if maxLots < req.Lots {
return nil, fmt.Errorf("%d lots available for %d-lot order", maxLots, req.Lots)
if maxEst.Lots < req.Lots {
return nil, fmt.Errorf("%d lots available for %d-lot order", maxEst.Lots, req.Lots)
}

// Get the estimate for the requested number of lots.
Expand Down
24 changes: 12 additions & 12 deletions client/asset/dcr/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,30 +688,30 @@ func (a amount) String() string {
// associated with nfo.MaxFeeRate. For quote assets, the caller will have to
// calculate lotSize based on a rate conversion from the base asset's lot size.
func (dcr *ExchangeWallet) MaxOrder(lotSize uint64, nfo *dex.Asset) (*asset.SwapEstimate, error) {
_, _, _, est, err := dcr.maxOrder(lotSize, nfo)
_, _, est, err := dcr.maxOrder(lotSize, nfo)
return est, err
}

// maxOrder gets the estimate for MaxOrder, and also returns the
// []*compositeUTXO to be used for further order estimation without additional
// calls to listunspent.
func (dcr *ExchangeWallet) maxOrder(lotSize uint64, nfo *dex.Asset) (utxos []*compositeUTXO, lots, feeRate uint64, est *asset.SwapEstimate, err error) {
// []*compositeUTXO and network fee rate to be used for further order estimation
// without additional calls to listunspent.
func (dcr *ExchangeWallet) maxOrder(lotSize uint64, nfo *dex.Asset) (utxos []*compositeUTXO, feeRate uint64, est *asset.SwapEstimate, err error) {
networkFeeRate, err := dcr.feeRate(1)
if err != nil {
return nil, 0, 0, nil, fmt.Errorf("error getting network fee estimate: %w", err)
return nil, 0, nil, fmt.Errorf("error getting network fee estimate: %w", err)
}

utxos, err = dcr.spendableUTXOs()
if err != nil {
return nil, 0, 0, nil, fmt.Errorf("error parsing unspent outputs: %w", err)
return nil, 0, nil, fmt.Errorf("error parsing unspent outputs: %w", err)
}
var avail uint64
for _, utxo := range utxos {
avail += toAtoms(utxo.rpc.Amount)
}

// Start by attempting max lots with no fees.
lots = avail / lotSize
lots := avail / lotSize
for lots > 0 {
est, _, err := dcr.estimateSwap(lots, lotSize, networkFeeRate, utxos, nfo, dcr.useSplitTx)
// The only failure mode of estimateSwap -> dcr.fund is when there is
Expand All @@ -721,10 +721,10 @@ func (dcr *ExchangeWallet) maxOrder(lotSize uint64, nfo *dex.Asset) (utxos []*co
lots--
continue
}
return utxos, lots, networkFeeRate, est, nil
return utxos, networkFeeRate, est, nil
}

return nil, 0, 0, &asset.SwapEstimate{}, nil
return nil, 0, &asset.SwapEstimate{}, nil
}

// estimateSwap prepares an *asset.SwapEstimate.
Expand Down Expand Up @@ -788,12 +788,12 @@ func (dcr *ExchangeWallet) PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, erro
// The utxo set is only used once right now, but when order-time options are
// implemented, the utxos will be used to calculate option availability and
// fees.
utxos, maxLots, feeRate, _, err := dcr.maxOrder(req.LotSize, req.AssetConfig)
utxos, feeRate, maxEst, err := dcr.maxOrder(req.LotSize, req.AssetConfig)
if err != nil {
return nil, err
}
if maxLots < req.Lots {
return nil, fmt.Errorf("%d lots available for %d-lot order", maxLots, req.Lots)
if maxEst.Lots < req.Lots {
return nil, fmt.Errorf("%d lots available for %d-lot order", maxEst.Lots, req.Lots)
}

// Get the estimate for the requested number of lots.
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/js/markets.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export default class MarketsPage extends BasePage {
this.drawChartLines()
})
bind(page.maxOrd, 'click', () => {
if (this.isSell()) page.lotField.value = this.market.maxSell.lots
if (this.isSell()) page.lotField.value = this.market.maxSell.swap.lots
else page.lotField.value = this.market.maxBuys[this.adjustedRate()].swap.lots
this.lotChanged()
})
Expand Down

0 comments on commit 0756b0b

Please sign in to comment.