-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathConvertModal.razor
146 lines (123 loc) · 3.62 KB
/
ConvertModal.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
@inject SwapStorage swapStorage;
@inject AccountStorage accountStorage;
@inject WalletStorage walletStorage;
@using Atomex.Swaps;
<div class="modal__container loading-container">
<div class="dark-background__no-grad modal-title">
@(State == States.Confirmation ? Translations.ConvertConfirmation :
State == States.Success || State == States.SuccessCreated ? Translations.Success :
State == States.Error ? Translations.ConvertingError :
State == States.CantConvert ? Translations.CantConvert : Translations.Converting)
</div>
@if (State == States.Converting) {
<Loader />
<div></div>
}
@if (State == States.Confirmation) {
<div class="modal-subtitle">
@(Translations.DoYouReallyWantToConvert):
</div>
<ConvertCard NoInfo="@true" />
<div class="send-confirmation__container convert">
<div>
<span class="send-confirmation__label convert">@(Translations.WithPrice):</span>
<span class="send-confirmation__coin">@Helper.DecimalToStr(swapStorage.EstimatedPrice)</span>
</div>
<div>
<span class="send-confirmation__label convert">
@(Translations.WithTotalNetworkFees):
</span>
<span class="send-confirmation__address">
$@(Helper.DecimalToStr(swapStorage.EstimatedTotalNetworkFeeInBase, "F2"))
</span>
</div>
</div>
<div class="modal-buttons-container">
<div>
<NavigateButton Variant="left" OnClick="@handleCancel">
@Translations.No
</NavigateButton>
<NavigateButton Variant="right" OnClick="@handleSend">
@Translations.Yes
</NavigateButton>
</div>
</div>
}
@if (State == States.Error) {
<div class="modal-subtitle">
@(ErrorText)
</div>
}
@if (State == States.CantConvert) {
<div class="modal-subtitle">
@(swapStorage.NotReadyConvertMessage)
</div>
}
@if (State == States.SuccessCreated) {
<div class="modal-subtitle">
@(Translations.SwapSuccessfullyCreated)
</div>
<div class="modal-subtitle">@(Translations.SwapNote)</div>
}
@if (State == States.Success) {
<div class="modal-subtitle">
@(Translations.SwapRequestCreated)
</div>
<div class="swap-await-loader-helper"></div>
<Loader ClassName="swap-await-loader" />
<div class="swap-await-loader-helper"></div>
}
@if (State == States.SuccessCreated || State == States.Error || State == States.CantConvert) {
<div class="modal-buttons-container">
<div>
<NavigateButton Variant="center" OnClick="@handleCancel">
OK
</NavigateButton>
</div>
</div>
}
</div>
@code {
[Parameter]
public EventCallback OnCancelClick { get; set; }
I18nText.Translations Translations = new I18nText.Translations();
protected override async Task OnInitializedAsync()
{
Translations = await I18nText.GetTextTableAsync<I18nText.Translations>(this);
swapStorage.RefreshRequested += StateHasChanged;
if (swapStorage.NotReadyConvertMessage != null)
{
State = States.CantConvert;
StateHasChanged();
}
}
private async void handleCancel()
{
await OnCancelClick.InvokeAsync(null);
}
private string ErrorText;
private async void handleSend()
{
State = States.Converting;
ErrorText = await swapStorage.Send();
if (ErrorText != null)
{
State = States.Error;
}
else
{
State = States.SuccessCreated;
}
StateHasChanged();
}
private States State { get; set; } = States.Confirmation;
private enum States
{
Confirmation,
Converting,
Error,
CantConvert,
Success,
SuccessCreated
}
}