Skip to content

Commit 231266d

Browse files
committed
Auto-broadcast visual timer, reset
1 parent 50a28ee commit 231266d

File tree

5 files changed

+51
-12
lines changed

5 files changed

+51
-12
lines changed

src/css/views/send.css

+12-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@
201201
background-image: url('../images/wink-dark.svg');
202202
}
203203
.view.send .button.secondary-control.reset {
204-
background-image: none;
205-
text-transform: lowercase;
204+
background-color: #333;
205+
background-image: url('../images/reset-dark.svg');
206206
}
207207
.view.send .form-row--amount .form-field.has-1-actions {
208208
padding-right: 4.6rem;
@@ -277,3 +277,13 @@
277277
.view.send .form-row + .form-row {
278278
margin-top: .8rem;
279279
}
280+
.view.send .auto-double-spend-timer {
281+
position: absolute;
282+
right: .9rem;
283+
top: 0;
284+
height: 3.2rem;
285+
line-height: 3.2rem;
286+
font-weight: 700;
287+
font-size: 1.2rem;
288+
color: rgba(255,255,255,.5);
289+
}

src/images/reset-dark.svg

+1
Loading

src/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ <h2 class="page-title">{{i18n "receive.title"}}</h2>
9797
</div>
9898
<div class="secondary-controls">
9999
<a class="secondary-control button payment disabled"></a>
100-
<a class="secondary-control button double-spend disabled"></a>
101-
<a class="secondary-control button reset disabled">{{i18n "send.reset"}}</a>
100+
<a class="secondary-control button double-spend disabled"><b class="auto-double-spend-timer"></b></a>
101+
<a class="secondary-control button reset disabled"></a>
102102
</div>
103103
</script>
104104

src/js/lang/en.js

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ app.lang['en'] = (function() {
5858
'send.error-insufficient-fee-confirm-retry': 'TRANSACTION REJECTED:\nInsufficient fee. Do you want to retry with the suggested fee of {{fee}} {{symbol}}?',
5959
'send.error-missing-inputs': 'TRANSACTION REJECTED:\nMissing inputs. It is possible that the payment transaction was already confirmed :(',
6060
'send.reset-confirm': 'Are you sure you want to reset? (The last double-spend tx will be lost)',
61-
'send.reset': 'Reset',
6261

6362
'services.electrum.failed-request.no-connected-servers': 'Unable to complete request - no connected Electrum servers',
6463

src/js/views/send.js

+36-7
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ app.views.Send = (function() {
146146
return app.i18n.t('send.auto-broadcast-double-spend.delay');
147147
},
148148
type: 'number',
149-
default: 3,
149+
default: 5,
150150
min: 0,
151151
step: 1,
152152
visible: true,
@@ -247,6 +247,7 @@ app.views.Send = (function() {
247247
symbol: this.$('.balance-symbol'),
248248
};
249249
this.$scoreboard = this.$('.scoreboard');
250+
this.$autoDoubleSpendTimer = this.$('.auto-double-spend-timer');
250251
this.pullFromCache();
251252
this.toggleFlags();
252253
this.updateAddress();
@@ -659,15 +660,42 @@ app.views.Send = (function() {
659660
var advOptions = this.getAdvancedOptions();
660661
var autoBroadcastDoubleSpend = advOptions.autoBroadcastDoubleSpend;
661662
if (autoBroadcastDoubleSpend) {
662-
var delay = parseInt(advOptions.autoBroadcastDoubleSpendDelay) * 1000;
663-
var doubleSpend = _.bind(this.doubleSpend, this, {
664-
skipConfirmation: true,
665-
});
666-
this.autoDoubleSpendTimer = _.delay(doubleSpend, delay);
663+
this.startAutoDoubleSpendTimer();
667664
}
668665
},
669-
doubleSpend: function(options) {
666+
startAutoDoubleSpendTimer: function() {
667+
this.clearedDoubleSpendTimer = false;
668+
var delay = this.getAutoDoubleSpendDelay();
669+
var endTime = Date.now() + delay;
670+
this.autoDoubleSpendTimer = _.delay(_.bind(this.doubleSpend, this, {
671+
skipConfirmation: true,
672+
}), delay);
673+
var updateAutoDoubleSpendTimer = _.bind(function() {
674+
if (!this.clearedDoubleSpendTimer) {
675+
var timeRemaining = Date.now() - endTime;
676+
if (timeRemaining < 500) {
677+
this.$autoDoubleSpendTimer.text(Math.abs(Math.round(timeRemaining / 1000)));
678+
return _.delay(updateAutoDoubleSpendTimer, 50);
679+
}
680+
}
681+
// Timer done or cleared.
682+
this.$autoDoubleSpendTimer.text('');
683+
return null;
684+
}, this);
685+
this.autoDoubleSpendUpdateTimer = updateAutoDoubleSpendTimer();
686+
},
687+
getAutoDoubleSpendDelay: function() {
688+
var advOptions = this.getAdvancedOptions();
689+
return parseInt(advOptions.autoBroadcastDoubleSpendDelay) * 1000;
690+
},
691+
clearAutoDoubleSpendTimer: function() {
692+
this.clearedDoubleSpendTimer = true;
693+
this.$autoDoubleSpendTimer.text('');
670694
clearTimeout(this.autoDoubleSpendTimer);
695+
clearTimeout(this.autoDoubleSpendUpdateTimer);
696+
},
697+
doubleSpend: function(options) {
698+
this.clearAutoDoubleSpendTimer();
671699
options = _.defaults(options || {}, {
672700
skipConfirmation: false,
673701
});
@@ -760,6 +788,7 @@ app.views.Send = (function() {
760788
},
761789
reset: function() {
762790
if (confirm(app.i18n.t('send.reset-confirm'))) {
791+
this.clearAutoDoubleSpendTimer();
763792
this.resetForm();
764793
}
765794
},

0 commit comments

Comments
 (0)