mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 02:28:31 +01:00
c71e671311
* Added custodian account trade support * UI updates * Improved UI spacing and field sizes + Fixed input validation * Reset error message when opening trade modal * Better error handing + test + surface error in trade modal in UI * Add delete confirmation modal * Fixed duplicate ID in site nav * Replace jQuery.ajax with fetch for onTradeSubmit * Added support for minimumTradeQty to trading pairs * Fixed LocalBTCPayServerClient after previous refactoring * Handling dust amounts + minor API change * Replaced jQuery with Fetch API + UX improvements + more TODOs * Moved namespace because Rider was unhappy * Major UI improvements when swapping or changing assets, fixed bugs in min trade qty, fixed initial qty after an asset change etc * Commented out code for easier debugging * Fixed missing default values Co-authored-by: Dennis Reimann <mail@dennisreimann.de>
64 lines
2.3 KiB
C#
64 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BTCPayServer.Abstractions.Constants;
|
|
using BTCPayServer.Abstractions.Custodians;
|
|
using BTCPayServer.Client.Models;
|
|
using BTCPayServer.Filters;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Cors;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace BTCPayServer.Controllers.Greenfield
|
|
{
|
|
[ApiController]
|
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.GreenfieldAPIKeys)]
|
|
[EnableCors(CorsPolicies.All)]
|
|
[ExperimentalRouteAttribute] // if you remove this, also remove "x_experimental": true in swagger.template.custodians.json
|
|
public class GreenfieldCustodianController : ControllerBase
|
|
{
|
|
private readonly IEnumerable<ICustodian> _custodianRegistry;
|
|
|
|
public GreenfieldCustodianController(IEnumerable<ICustodian> custodianRegistry)
|
|
{
|
|
_custodianRegistry = custodianRegistry;
|
|
}
|
|
|
|
[HttpGet("~/api/v1/custodians")]
|
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
|
public IActionResult ListCustodians()
|
|
{
|
|
var all = _custodianRegistry.ToList().Select(ToModel);
|
|
return Ok(all);
|
|
}
|
|
|
|
private CustodianData ToModel(ICustodian custodian)
|
|
{
|
|
var result = new CustodianData();
|
|
result.Code = custodian.Code;
|
|
result.Name = custodian.Name;
|
|
|
|
if (custodian is ICanTrade tradableCustodian)
|
|
{
|
|
var tradableAssetPairs = tradableCustodian.GetTradableAssetPairs();
|
|
var tradableAssetPairsDict = new Dictionary<string, AssetPairData>(tradableAssetPairs.Count);
|
|
foreach (var tradableAssetPair in tradableAssetPairs)
|
|
{
|
|
tradableAssetPairsDict.Add(tradableAssetPair.ToString(), tradableAssetPair);
|
|
}
|
|
result.TradableAssetPairs = tradableAssetPairsDict;
|
|
}
|
|
|
|
if (custodian is ICanDeposit depositableCustodian)
|
|
{
|
|
result.DepositablePaymentMethods = depositableCustodian.GetDepositablePaymentMethods();
|
|
}
|
|
if (custodian is ICanWithdraw withdrawableCustodian)
|
|
{
|
|
result.WithdrawablePaymentMethods = withdrawableCustodian.GetWithdrawablePaymentMethods();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|
|
}
|