Skip to content

Commit 7dd1e30

Browse files
committed
ui+pool: disable buttons during account changes
1 parent a850b51 commit 7dd1e30

File tree

8 files changed

+39
-6
lines changed

8 files changed

+39
-6
lines changed

app/src/components/pool/account/CloseAccountConfirm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const CloseAccountConfirm: React.FC = () => {
5757
<Button
5858
danger
5959
ghost
60-
disabled={!closeAccountView.isValid}
60+
disabled={!closeAccountView.isValid || closeAccountView.loading}
6161
onClick={closeAccountView.closeAccount}
6262
>
6363
{l('common.confirm')}

app/src/components/pool/account/FundAccountConfirm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const FundAccountConfirm: React.FC = () => {
4949
<Button
5050
primary
5151
ghost
52-
disabled={!fundAccountView.isValid}
52+
disabled={!fundAccountView.isValid || fundAccountView.loading}
5353
onClick={fundAccountView.fundAccount}
5454
>
5555
{l('common.confirm')}

app/src/components/pool/account/FundNewAccountConfirm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const FundNewAccountConfirm: React.FC = () => {
6363
<Button
6464
primary
6565
ghost
66-
disabled={!fundNewAccountView.isValid}
66+
disabled={!fundNewAccountView.isValid || fundNewAccountView.loading}
6767
onClick={fundNewAccountView.fundAccount}
6868
>
6969
{l('common.confirm')}

app/src/components/pool/account/RenewAccountConfirm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const RenewAccountConfirm: React.FC = () => {
6464
<Button
6565
primary
6666
ghost
67-
disabled={!renewAccountView.isValid}
67+
disabled={!renewAccountView.isValid || renewAccountView.loading}
6868
onClick={renewAccountView.renewAccount}
6969
>
7070
{l('common.confirm')}

app/src/store/views/closeAccountView.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export default class CloseAccountView {
1010
destination = '';
1111
satsPerVbyte = 0;
1212

13+
loading = false;
14+
1315
constructor(store: Store) {
1416
makeAutoObservable(this, {}, { deep: false, autoBind: true });
1517

@@ -55,6 +57,10 @@ export default class CloseAccountView {
5557
this.satsPerVbyte = satPerVbyte;
5658
}
5759

60+
setLoading(loading: boolean) {
61+
this.loading = loading;
62+
}
63+
5864
//
5965
// Actions
6066
//
@@ -75,10 +81,12 @@ export default class CloseAccountView {
7581
async closeAccount() {
7682
if (!this.isValid) return;
7783

84+
this.setLoading(true);
7885
try {
7986
await this._store.orderStore.cancelAllOrders();
8087
} catch (error) {
81-
this._store.appView.handleError(error, 'Unable to cancel all open orders');
88+
this._store.appView.handleError(error as Error, 'Unable to cancel all open orders');
89+
this.setLoading(false);
8290
return;
8391
}
8492

@@ -92,5 +100,6 @@ export default class CloseAccountView {
92100
if (txid) {
93101
this.cancel();
94102
}
103+
this.setLoading(false);
95104
}
96105
}

app/src/store/views/fundAccountView.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export default class FundAccountView {
1212
amount = 0;
1313
satsPerVbyte = 0;
1414

15+
loading = false;
16+
1517
constructor(store: Store) {
1618
makeAutoObservable(this, {}, { deep: false, autoBind: true });
1719

@@ -66,6 +68,10 @@ export default class FundAccountView {
6668
this.satsPerVbyte = satPerVbyte;
6769
}
6870

71+
setLoading(loading: boolean) {
72+
this.loading = loading;
73+
}
74+
6975
//
7076
// Actions
7177
//
@@ -84,6 +90,7 @@ export default class FundAccountView {
8490

8591
/** submits the deposit to the API and resets the form values if successful */
8692
async fundAccount() {
93+
this.setLoading(true);
8794
const satsPerKWeight = this._store.api.pool.satsPerVByteToKWeight(this.satsPerVbyte);
8895

8996
// if there is an error, it will be displayed by deposit
@@ -92,5 +99,6 @@ export default class FundAccountView {
9299
if (txid) {
93100
this.cancel();
94101
}
102+
this.setLoading(false);
95103
}
96104
}

app/src/store/views/fundNewAccountView.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export default class FundNewAccountView {
1919
// response from quote
2020
minerFee = Big(0);
2121

22+
loading = false;
23+
2224
constructor(store: Store) {
2325
makeAutoObservable(this, {}, { deep: false, autoBind: true });
2426

@@ -104,6 +106,10 @@ export default class FundNewAccountView {
104106
this.expireBlocks = expireBlocks;
105107
}
106108

109+
setLoading(loading: boolean) {
110+
this.loading = loading;
111+
}
112+
107113
//
108114
// Actions
109115
//
@@ -131,12 +137,13 @@ export default class FundNewAccountView {
131137

132138
this._store.accountSectionView.showFundNewConfirm();
133139
} catch (error) {
134-
this._store.appView.handleError(error, 'Unable to estimate miner fee');
140+
this._store.appView.handleError(error as Error, 'Unable to estimate miner fee');
135141
}
136142
}
137143

138144
/** submits the order to the API and resets the form values if successful */
139145
async fundAccount() {
146+
this.setLoading(true);
140147
// if there is an error, it will be displayed by createAccount
141148
const traderKey = await this._store.accountStore.createAccount(
142149
this.amount,
@@ -147,5 +154,6 @@ export default class FundNewAccountView {
147154
if (traderKey) {
148155
this.cancel();
149156
}
157+
this.setLoading(false);
150158
}
151159
}

app/src/store/views/renewAccountView.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export default class RenewAccountView {
1212
expiryBlocks = DEFAULT_EXPIRE_BLOCKS;
1313
satsPerVbyte = 0;
1414

15+
loading = false;
16+
1517
constructor(store: Store) {
1618
makeAutoObservable(this, {}, { deep: false, autoBind: true });
1719

@@ -55,6 +57,10 @@ export default class RenewAccountView {
5557
this.satsPerVbyte = satsPerVbyte;
5658
}
5759

60+
setLoading(loading: boolean) {
61+
this.loading = loading;
62+
}
63+
5864
//
5965
// Actions
6066
//
@@ -75,6 +81,7 @@ export default class RenewAccountView {
7581
async renewAccount() {
7682
if (!this.isValid) return;
7783

84+
this.setLoading(true);
7885
const satsPerKWeight = this._store.api.pool.satsPerVByteToKWeight(this.satsPerVbyte);
7986
// if there is an error, it will be displayed by renewAccount
8087
const txid = await this._store.accountStore.renewAccount(
@@ -85,5 +92,6 @@ export default class RenewAccountView {
8592
if (txid) {
8693
this.cancel();
8794
}
95+
this.setLoading(false);
8896
}
8997
}

0 commit comments

Comments
 (0)