btcpayserver/Plugins/BTCPayServer.Plugins.Custodians.FakeCustodian/FakeCustodian.cs
Wouter Samaey 6f2b673021
Custodian withdrawal support + Some refactoring and cleanup (#4085)
* Renamed "WithdrawAsync" to "WithdrawToStoreWalletAsync"

* WIP

* WIP withdrawal + Refactored Form saving to JObject

* WIP

* Form to fix bad values during withdrawing appears correctly

* WIP

* Lots of cleanup and refactoring + Password field and toggle password view

* Cleanup + Finishing touches on withdrawals

* Added "Destination" dummy text as this is always the destination.

* Fixed broken test

* Added support for withdrawing using qty as a percentage if it ends with "%". Needs more testing.

* Fixed broken build

* Fixed broken build (2)

* Update BTCPayServer/wwwroot/swagger/v1/swagger.template.custodians.json

Co-authored-by: d11n <mail@dennisreimann.de>

* Update BTCPayServer/wwwroot/swagger/v1/swagger.template.custodians.json

Co-authored-by: d11n <mail@dennisreimann.de>

* Improved unit tests

* Fixed swagger bug

* Test improvements

Make string conversion of quantity explicitely.

* Fix build warnings

* Swagger: Add missing operationId

* Made change Dennis requested

* Removed unused file

* Removed incorrect comment

* Extra contructor

* Renamed client methods

* Cleanup config before saving

* Fixed broken controller

* Refactor custodian

* Fix build

* Make decimal fields strings to match the rest of Greenfield

* Improve parsing of % quantities

---------

Co-authored-by: d11n <mail@dennisreimann.de>
Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
2023-03-20 10:45:32 +09:00

74 lines
2.3 KiB
C#

using BTCPayServer.Abstractions.Custodians;
using BTCPayServer.Abstractions.Form;
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Plugins.Custodians.FakeCustodian;
public class FakeCustodian : ICustodian
{
public string Code
{
get => "fake";
}
public string Name
{
get => "Fake Exchange";
}
public Task<Dictionary<string, decimal>> GetAssetBalancesAsync(JObject config, CancellationToken cancellationToken)
{
var fakeConfig = ParseConfig(config);
var r = new Dictionary<string, decimal>()
{
{ "BTC", fakeConfig.BTCBalance },
{ "LTC", fakeConfig.LTCBalance },
{ "USD", fakeConfig.USDBalance },
{ "EUR", fakeConfig.EURBalance }
};
return Task.FromResult(r);
}
public Task<Form> GetConfigForm(CancellationToken cancellationToken = default)
{
var form = new Form();
var fieldset = Field.CreateFieldset();
// Maybe a decimal type field would be better?
var fakeBTCBalance = Field.Create("BTC Balance", "BTCBalance", null, true,
"Enter the amount of BTC you want to have.");
var fakeLTCBalance = Field.Create("LTC Balance", "LTCBalance", null, true,
"Enter the amount of LTC you want to have.");
var fakeEURBalance = Field.Create("EUR Balance", "EURBalance", null, true,
"Enter the amount of EUR you want to have.");
var fakeUSDBalance = Field.Create("USD Balance", "USDBalance", null, true,
"Enter the amount of USD you want to have.");
fieldset.Label = "Your fake balances";
fieldset.Fields.Add(fakeBTCBalance);
fieldset.Fields.Add(fakeLTCBalance);
fieldset.Fields.Add(fakeEURBalance);
fieldset.Fields.Add(fakeUSDBalance);
form.Fields.Add(fieldset);
return Task.FromResult(form);
}
private FakeCustodianConfig ParseConfig(JObject config)
{
return config?.ToObject<FakeCustodianConfig>() ?? throw new InvalidOperationException("Invalid config");
}
}
public class FakeCustodianConfig
{
public decimal BTCBalance { get; set; }
public decimal LTCBalance { get; set; }
public decimal USDBalance { get; set; }
public decimal EURBalance { get; set; }
public FakeCustodianConfig()
{
}
}