/
actions.js
155 lines (138 loc) · 2.9 KB
/
actions.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
/*
*
* SendToken actions
*
*/
import {
CHANGE_AMOUNT,
CHANGE_FROM,
CHANGE_TO,
CHANGE_GAS_PRICE,
COMFIRM_SEND_TRANSACTION,
COMFIRM_SEND_TRANSACTION_SUCCESS,
COMFIRM_SEND_TRANSACTION_ERROR,
ABORT_TRANSACTION,
SEND_TRANSACTION,
SEND_TRANSACTION_SUCCESS,
SEND_TRANSACTION_ERROR,
} from './constants';
/**
* Update from address and token, both parameters are optional
* @param {string} [address] '0xffd..'
* @param {object} [sendTokenSymbol] tokens to send (eth not included)
*
* @return {object} An action object with a type of CHANGE_FROM, address and sendTokenSymbol
*/
export function changeFrom(address, sendTokenSymbol) {
return {
type: CHANGE_FROM,
address,
sendTokenSymbol,
};
}
export function changeAmount(amount) {
return {
type: CHANGE_AMOUNT,
amount,
};
}
export function changeTo(inputAddress) {
// remove unnessesery spaces
const address = inputAddress.replace(/^\s+|\s+$/g, '');
return {
type: CHANGE_TO,
address,
};
}
export function changeGasPrice(gasPrice) {
if (gasPrice === '') {
return {
type: CHANGE_GAS_PRICE,
gasPrice: 0,
};
}
return {
type: CHANGE_GAS_PRICE,
gasPrice,
};
}
/**
* initiate confirmation object
*
* @return {object} An action object with a type of COMFIRM_SEND_TRANSACTION
*/
export function confirmSendTransaction() {
return {
type: COMFIRM_SEND_TRANSACTION,
};
}
/**
* transaction confirmed successfully
*
* @return {object} An action object with a type of COMFIRM_SEND_TRANSACTION_SUCCESS
*/
export function confirmSendTransactionSuccess(msg) {
if (msg) {
return {
type: COMFIRM_SEND_TRANSACTION_SUCCESS,
msg,
};
}
return {
type: COMFIRM_SEND_TRANSACTION_SUCCESS,
msg: 'Transaction confirmed successfully, Send to transmit',
};
}
/**
* Error confirming transaction
*
* @return {object} An action object with a type of COMFIRM_SEND_TRANSACTION_ERROR
*/
export function confirmSendTransactionError(error) {
return {
type: COMFIRM_SEND_TRANSACTION_ERROR,
error,
};
}
/**
* Abort transaction aftrer it has been confirmed
*
* @return {object} An action object with a type of ABORT_TRANSACTION
*/
export function abortTransaction() {
return {
type: ABORT_TRANSACTION,
};
}
/**
* initiate Send
*
* @return {object} An action object with a type of SEND_TRANSACTION
*/
export function sendTransaction() {
return {
type: SEND_TRANSACTION,
};
}
/**
* transaction sent successfully
*
* @return {object} An action object with a type of SEND_TRANSACTION_SUCCESS
*/
export function sendTransactionSuccess(tx) {
return {
type: SEND_TRANSACTION_SUCCESS,
tx,
};
}
/**
* Error sending transaction
*
* @return {object} An action object with a type of SEND_TRANSACTION_ERROR
*/
export function sendTransactionError(error) {
return {
type: SEND_TRANSACTION_ERROR,
error,
};
}