forked from ethers/MultiSigWallet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
filters.js
176 lines (176 loc) · 5.26 KB
/
filters.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
(
function () {
angular
.module("multiSigWeb")
.filter('objectToArray', function () {
return function (objectMap) {
var returnedArray = [];
if (objectMap) {
var keys = Object.keys(objectMap);
for (var i=0; i<keys.length; i++) {
returnedArray.push(objectMap[keys[i]]);
}
}
return returnedArray;
};
})
.filter('fromNow', function () {
return function(dateString) {
if (!dateString) {
return null;
}
return moment(new Date(dateString)).fromNow();
};
})
.filter('address', function () {
return function(address) {
if(address && address.length > 3){
return address.slice(0, 12) + "...";
}
};
})
.filter('bigNumber', function () {
return function (big) {
if (big) {
return new Web3().toBigNumber(big).toNumber();
}
};
})
.filter('txData', function () {
return function (data) {
if (data) {
if (data == "0x") {
return "";
}
else if(data.length > 3 && data.length < 10) {
return data.slice(0, 10);
}
else if (data.length > 3 && data.length > 10) {
return data.slice(0, 10) + "...";
}
}
};
})
.filter('logParam', function ($filter) {
return function (log, isEther) {
if (log && Array.isArray(log)) {
return log.reduce(function (finalString, address) {
if (address.indexOf("0x") == -1){
return finalString + address + ", ";
}
else{
return finalString + address.slice(0, 20) + "..., ";
}
}, "").slice(0, -2);
}
else if (log === "0x0") {
return "0x0";
}
else if(log && log.indexOf && log.indexOf("0x") != -1){
return log.slice(0, 10) + "...";
}
else if ( log && log.match(/^[0-9]+$/) !== null) {
if (isEther) {
return $filter('ether')(log);
}
else if(log.toString().length < 8){
return log.toString().slice(0, 7);
}
else{
return new Web3().toBigNumber(log).toExponential(3);
}
}
else {
return log;
}
};
})
.filter('ether', function () {
return function (num) {
if (num) {
var casted = new Web3().toBigNumber(num).div('1e18');
if (casted.gt(0)) {
return casted.toPrecision(Math.floor(Math.log(casted.toNumber())/Math.log(10) + 3)).toString(10) + " ETH";
}
else {
return "0.00 ETH";
}
}
return null;
};
})
.filter('token', function () {
return function (token) {
if (token && token.balance) {
var decimals = token.decimals;
if(token.decimals === undefined){
decimals = 18;
}
var string_split = new Web3().toBigNumber(token.balance).div("1e" + decimals).toString(10).split('.');
var new_string = "";
var places = string_split[0].length - 1;
for (var i=places; i>=0; i--) {
new_string = string_split[0][i] + new_string;
if (i > 0 && (places - i + 1) % 3 === 0) {
new_string = ',' + new_string;
}
}
if (string_split.length == 2) {
new_string += '.' + string_split[1].substring(0, 2);
}
return new_string + " " + token.symbol;
}
else if (token && token.symbol){
return "0 "+ token.symbol;
}
else{
return null;
}
};
})
.filter('reverse', function () {
return function (items) {
return items.slice().reverse();
};
})
.filter('dashIfEmpty', function ($sce){
return function (text){
return text || text === 0 ? $sce.trustAsHtml(text.toString()) : $sce.trustAsHtml("<p class='text-center'>\n-\n</p>");
};
})
.filter('addressCanBeOwner', function (Wallet) {
return function (addressCandidate) {
if (addressCandidate && Array.isArray(addressCandidate)) {
for (key in Wallet.wallets) {
var wallet = Wallet.wallets[key];
return addressCandidate.map(function (address) {
if ( wallet && wallet.owners && wallet.owners[address] && wallet.owners[address].name){
return wallet.owners[address].name;
}
else {
return address;
}
});
}
}
else if (addressCandidate && addressCandidate.indexOf && addressCandidate.indexOf("0x") != -1) {
for (key in Wallet.wallets) {
var wallet = Wallet.wallets[key];
if ( wallet && wallet.owners && wallet.owners[addressCandidate] && wallet.owners[addressCandidate].name){
return wallet.owners[addressCandidate].name;
}
}
return addressCandidate;
}
else {
return addressCandidate;
}
};
})
.filter('formatEventName', function (){
return function (text){
return text.split(/(?=[A-Z])/).join(' ');
};
});
}
)();