forked from ethers/MultiSigWallet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
directives.js
124 lines (121 loc) · 3.85 KB
/
directives.js
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
(
function () {
angular
.module("multiSigWeb")
.directive('convertToNumber', function () {
return {
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
ngModel.$parsers.push(function (val) {
return val !== null ? parseInt(val, 10) : null;
});
ngModel.$formatters.push(function (val) {
return val !== null ? '' + val : null;
});
}
};
})
.directive('disabledIfNoAccounts', function (Wallet) {
return {
link: function(scope, element, attrs){
Wallet.webInitialized.then(
function () {
scope.$watch(function(){
if(Wallet.coinbase) {
element.removeAttr('disabled');
}
else {
attrs.$set('disabled', 'disabled');
}
});
}
);
}
};
})
.directive('showHideByConnectivity', function (Connection) {
return {
link: function(scope, element, attrs){
/*
* The HTML is shown by considering the 'showHideByConnectivity'
* attribute and looking up at the Connection.isConnected variable.
* Admitted attributes are 'online|offline'.
*/
scope.$watch(function(){
if(!Connection.isConnected && attrs.showHideByConnectivity=='online') {
element.css("display", "none");
}
else if(Connection.isConnected && attrs.showHideByConnectivity=='offline') {
element.css("display", "none");
}
else {
element.css("display", "");
}
});
}
};
})
.directive('showHideByFactoryStatus', function (Wallet, Connection) {
return {
link: function(scope, element, attrs){
/*
* The HTML is shown by considering the 'showHideByConnectivity'
* attribute and looking up at the Connection.isConnected variable.
* Admitted attributes are 'online|offline'.
*/
scope.$watch(function (){
return txDefault.walletFactoryAddress;
},
function(){
var address = Object.assign({}, txDefault, JSON.parse(localStorage.getItem("userConfig"))).walletFactoryAddress;
if (address) {
Wallet.web3.eth.getCode(address, function (e, factory) {
if (!Connection.isConnected) {
element.css("display", "none");
}
else if (factory && factory.length > 100) {
if (attrs.showHideByFactoryStatus=='online') {
element.css("display", "");
}
else {
element.css("display", "none");
}
}
else {
if (attrs.showHideByFactoryStatus=='offline') {
element.css("display", "");
}
else {
element.css("display", "none");
}
}
});
}
else {
if (attrs.showHideByFactoryStatus=='online') {
element.css("display", "none");
}
}
});
}
};
})
.directive('valueOrDashByConnectivity', function (Connection) {
return {
link: function(scope, element, attrs) {
/*
* The value is shown by considering the
* Connection.isConnected variable.
*/
scope.$watch(function () {
if (!Connection.isConnected) {
element.html("-");
} else {
element.html(attrs.valueOrDashByConnectivity);
}
});
}
};
});
}
)();