-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddressInput.js
More file actions
120 lines (95 loc) · 3.11 KB
/
addressInput.js
File metadata and controls
120 lines (95 loc) · 3.11 KB
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
/**
Template Controllers
@module Templates
*/
/**
The address input template, containg the identicon.
@class [template] dapp_addressInput
@constructor
*/
Template['dapp_addressInput'].onCreated(function(){
// default set to true, to show no error
TemplateVar.set('isValid', true);
TemplateVar.set('isChecksum', true);
if(this.data && this.data.value) {
TemplateVar.set('value', this.data.value);
console.log('value: ', this.data.value);
}
});
Template['dapp_addressInput'].onRendered(function(){
if(this.data && this.data.value) {
this.$('input').trigger('change');
}
});
Template['dapp_addressInput'].helpers({
/**
Return the to address
@method (address)
*/
'address': function(){
var address = TemplateVar.get('value');
if(Template.instance().view.isRendered && Template.instance().find('input').value !== address)
Template.instance().$('input').trigger('change');
// return (_.isString(address)) ? '0x'+ address.replace('0x','') : false;
return (_.isString(address)) ? address : false;
},
/**
Return the autofocus or disabled attribute.
@method (additionalAttributes)
*/
'additionalAttributes': function(){
var attr = {};
if(this.autofocus)
attr.autofocus = true;
if(this.disabled)
attr.disabled = true;
return attr;
},
/**
Get the correct text, if TAPi18n is available.
@method i18nText
*/
'i18nText': function(){
if(typeof TAPi18n === 'undefined' || TAPi18n.__('elements.checksumAlert') == 'elements.checksumAlert') {
return "This address looks valid, but it doesn't have some security features that will protect you against typos, so double check you have the right one. If provided, check if the security icon matches.";
} else {
return TAPi18n.__('elements.checksumAlert');
}
}
});
Template['dapp_addressInput'].events({
/**
Set the address while typing
@event input input, change input
*/
'input input, change input': function(e, template){
var value = e.currentTarget.value.replace(/\s+/g, '');
// add 0x
// if(value.length > 2 && value.indexOf('0x') === -1) {
// value = '0x'+ value;
// e.currentTarget.value = value;
// }
if(web3.isAddress(value) || _.isEmpty(value)) {
TemplateVar.set('isValid', true);
if(!_.isEmpty(value)) {
// TemplateVar.set('value', '0x'+ value.replace('0x',''));
TemplateVar.set('value', value);
TemplateVar.set('isChecksum', web3.isChecksumAddress(value));
} else {
TemplateVar.set('value', undefined);
TemplateVar.set('isChecksum', true);
}
} else {
TemplateVar.set('isValid', false);
TemplateVar.set('value', undefined);
}
},
/**
Prevent the identicon from beeing clicked.
TODO: remove?
@event click a
*/
'click a': function(e){
e.preventDefault();
}
});