forked from Borodutch/fondu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contract-constructor.js
106 lines (103 loc) · 2.42 KB
/
contract-constructor.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
const upd = function() {
this.updateCode()
}
var app = new Vue({
el: '#contract-constructor',
data: {
name: null,
symbol: null,
decimals: null,
rate: null,
wallet: '',
timed: false,
startDate: null,
endDate: null,
refundable: false,
goal: null,
increasingPrice: false,
startRate: null,
endRate: null,
capped: false,
cap: null,
whitelisted: false,
supply: null,
code: 'Loading...'
},
created: upd,
watch: {
name: upd,
symbol: upd,
decimals: upd,
rate: upd,
wallet: upd,
timed: upd,
startDate: upd,
endDate: upd,
refundable: upd,
goal: upd,
increasingPrice: upd,
startRate: upd,
endRate: upd,
capped: upd,
cap: upd,
whitelisted: upd,
},
methods: {
updateCode: function() {
const contructConstructor =
new ContractConstructor(
this.name,
this.symbol,
this.decimals,
this.rate,
this.wallet,
this.getContractOptions(),
this.getContractParams());
contructConstructor.getCodeText()
.then(res => this.code = res)
},
download: function() {
const contructConstructor =
new ContractConstructor(
this.name,
this.symbol,
this.decimals,
this.rate,
this.wallet,
this.getContractOptions(),
this.getContractParams());
contructConstructor.getCode()
.then(res => saveAs(res, `${this.symbol || 'MYT'}Code.zip`))
},
getContractOptions: function() {
const options = []
if (this.timed) {
options.push(ContractOptions.Timed)
if (this.refundable) options.push(ContractOptions.Refundable)
if (this.increasingPrice) options.push(ContractOptions.IncreasingPrice)
}
if (this.capped) {
options.push(ContractOptions.Capped)
}
if (this.whitelisted) {
options.push(ContractOptions.Whitelisted)
}
return options
},
getContractParams: function() {
const params = []
if (this.timed) {
params.push([this.startDate, this.endDate])
if (this.refundable) params.push([this.goal])
if (this.increasingPrice) params.push([this.startRate, this.endRate])
}
if (this.capped) {
params.push([this.cap])
}
if (this.whitelisted) {
params.push([])
}
return params
}
},
})