123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- @using Microsoft.AspNetCore.Components.Web
- <div class="modal" tabindex="-1" role="dialog" style="display:none" id="@elementid">
- <div class="modal-container">
- <div class="modal__body">
- <div class="modal__body__header">
- <div class="modal__body__header__info">
- <img src="img/packet.svg" alt="">
- <p>Цифровые активы</p>
- </div>
- @*<div class="modal__body__header__href">
- <a href="">Balans</a>
- <a href="">Swap</a>
- <a href="">Liquidity</a>
- </div>*@
- </div>
- <div class="modal__body__container">
- <div class="modal__body__container__left">
- <div class="modal__body__calc__balance__header">
- <p>БАЛАНСЫ [@bc_selected]</p>
- @*<button class="btn_orange">История</button>*@
- </div>
- <div class="modal__body__calc__balance__numbers">
- <div class="modal__body__calc__balance__numbers__name">
- <p>Система</p>
- </div>
- <div class="modal__body__calc__balance__numbers__value">
- <div class="modal__body__calc__balance__numbers__value__item">
- <p>@systemEth</p>
- <p>ETH</p>
- </div>
- <div class="modal__body__calc__balance__numbers__value__item">
- <p>@systemToken</p>
- <p>QNM</p>
- </div>
- </div>
- </div>
- <div><p>@_account.Name</p></div>
- <div class="modal__body__calc__balance__numbers">
- <div class="modal__body__calc__balance__numbers__name">
- <p>Ваш</p>
- </div>
- <div class="modal__body__calc__balance__numbers__value">
- <div class="modal__body__calc__balance__numbers__value__item">
- <p>@ethBalance</p>
- <p>ETH</p>
- </div>
- <div class="modal__body__calc__balance__numbers__value__item">
- <p>@tokenBalance</p>
- <p>QNM</p>
- </div>
- </div>
- </div>
- @*<div class="modal__body__calc__balance__button">
- <button class="btn_orange btn_center">Пополнение</button>
- <button class="btn_orange btn_center">Вывод</button>
- </div>*@
- </div>
- <div class="modal__body__container__right">
- <p class="modal__body__calc__change__header">Обмен</p>
- <p class="modal__body__calc__change__desc">Trade tokens in an istant</p>
- <div class="modal__input__box" place="From" balanc=@chosenBalanceFrom>
- <input @bind=fromInput @bind:event="oninput" type="text" class="modal__input">
- <select @bind="from_token_selected" type="select" class="modal__select">
- <option value="eth">ETH</option>
- <option value="qnm">QNM</option>
- </select>
- </div>
- <div class="modal__input__box" place="To" balanc=@chosenBalanceTo>
- <input @bind=toInput @bind:event="oninput" type="text" class="modal__input">
- <select @bind="to_token_selected" type="select" class="modal__select">
- <option value="qnm">QNM</option>
- <option value="eth">ETH</option>
- </select>
- </div>
- @*<div class="modal__input__total">
- <p>Price</p>
- <div class="modal_input_total_value">
- <p>1.000000050</p>
- <p>2DH</p>
- </div>
- </div>*@
- <div class="modal__input__button">
- <button @onclick="@Ok" class="btn_orange btn_center">ОК</button>
- </div>
- </div>
- </div>
- </div>
- <a class="modal_close" style="cursor:pointer" @onclick="@Close">✖</a>
- </div>
- </div>
- @code {[Inject]
- public IJSRuntime JsRuntime { get; set; }
- [Parameter]
- public RenderFragment Title { get; set; }
- string ethBalance;
- string tokenBalance;
- string chosenBalanceFrom;
- string chosenBalanceTo;
- string bc_selected;
- string fi;
- string ti;
- long lastInput = 0;
- string systemEth;
- string systemToken;
- string fromInput
- {
- get { return fi;
- }
- set { fi = value;
- System.Threading.Thread.Sleep(1);
- var now = DateTimeOffset.Now.ToUnixTimeSeconds();
- if (now - lastInput > 0)
- {
- try
- {
- var val = float.Parse(fi, System.Globalization.CultureInfo.InvariantCulture);
- //var val = System.Convert.ToSingle(fi);
- if (to_token_selected == "qnm")
- val *= 1000f;
- else
- val /= 1000f;
- ti = val.ToString();
- }
- catch (Exception e)
- {
- toInput = "0";
- Console.WriteLine(e.Message);
- }
- }
- lastInput = DateTimeOffset.Now.ToUnixTimeSeconds();
- }
- }
- string toInput
- {
- get { return ti; }
- set { ti = value;
- lastInput = DateTimeOffset.Now.ToUnixTimeSeconds();
- System.Threading.Thread.Sleep(1);
- var now = DateTimeOffset.Now.ToUnixTimeSeconds();
- if (now - lastInput > 0)
- {
- try
- {
- var val = float.Parse(ti, System.Globalization.CultureInfo.InvariantCulture);
- if (to_token_selected == "eth")
- val *= 1000f;
- else
- val /= 1000f;
- fi = val.ToString();
- }
- catch (Exception e)
- {
- fromInput = "0";
- Console.WriteLine(e.Message);
- }
- }
- }
- }
- string ft;
- string from_token_selected
- {
- get {
- return ft;
- }
- set {
- if (value == "eth")
- {
- to_token_selected = "qnm";
- chosenBalanceFrom = ethBalance;
- chosenBalanceTo = tokenBalance;
- }
- else
- {
- to_token_selected = "eth";
- chosenBalanceFrom = tokenBalance;
- chosenBalanceTo = ethBalance;
- }
- ft = value;
- }
- }
- string to_token_selected = "qnm";
- string elementid = "modal_assets";
- Models.AccountModel _account = new();
- @using Models;Blockchain bcMain;
- public async Task Balances()
- {
- ethBalance = await _account.GetBalance();
- var bc = await _account.GetSelectedBlockChain();
- bc_selected = bc.name;
- if (bc.port == 8666)
- {
- tokenBalance = await bc.BalanceOf(Blockchain.QNMAddress, _account.GetActualAddress(bc));
- systemEth = await bc.GetBalance(Blockchain.MultiOwnerContractRinkeby);
- systemToken = await bc.GetBalanceToken(Blockchain.QNMAddress, Blockchain.MultiOwnerContractRinkeby);
- Console.WriteLine($"systemToken {systemToken}");
- }
- else
- tokenBalance = "0";
- }
- public async Task Open(Models.AccountModel account)
- {
- _account = account;
- await Balances();
- await JsRuntime.InvokeVoidAsync("OpenModal", elementid);
- }
- public async Task Ok()
- {
- bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure?");
- if (confirmed)
- {
- Console.WriteLine("true");
- var bc = await _account.GetSelectedBlockChain();
- await bc.ExchangeCurrency(from_token_selected, to_token_selected, Blockchain.QNMAddress, _account.GetActualAddress(bc), fi, ti);
- //run change - recalculate balances
- }
- else
- {
- Console.WriteLine("false");
- //cancel
- }
- await Balances();
- }
- public void Close()
- {
- JsRuntime.InvokeVoidAsync("CloseModal", elementid);
- }
- }
|