/
retire_action.js
54 lines (48 loc) · 2.02 KB
/
retire_action.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
/*
Copyright: Ambrosus Inc.
Email: tech@ambrosus.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
This Source Code Form is “Incompatible With Secondary Licenses”, as defined by the Mozilla Public License, v. 2.0.
*/
import {constants} from 'ambrosus-node-contracts';
const isAtlasWithBundles = async (onboardActions) => {
const role = await onboardActions.rolesWrapper.onboardedRole(onboardActions.rolesWrapper.defaultAddress);
if (role === constants.ATLAS) {
return await onboardActions.atlasStakeWrapper.isShelteringAny(onboardActions.atlasStakeWrapper.defaultAddress);
}
return false;
};
const retireAction = (atlasModeModel, onboardActions, confirmRetirementDialog, retirementSuccessfulDialog, continueAtlasRetirementDialog, retirementStartSuccessfulDialog, retirementContinueDialog, retirementStopDialog, genericErrorDialog) => async () => {
if (await isAtlasWithBundles(onboardActions)) {
const retireMode = (await atlasModeModel.getMode()).mode === 'retire';
if (retireMode) {
if ((await continueAtlasRetirementDialog()).continueConfirmation) {
await retirementContinueDialog();
} else {
if (await atlasModeModel.setMode('normal')) {
await retirementStopDialog();
return true;
}
await genericErrorDialog('Can not set normal mode: I/O error');
return false;
}
return true;
}
if (!(await confirmRetirementDialog()).retirementConfirmation) {
return false;
}
if (await atlasModeModel.setMode('retire')) {
await retirementStartSuccessfulDialog();
return true;
}
await genericErrorDialog('Can not set retire mode: I/O error');
return false;
}
if (!(await confirmRetirementDialog()).retirementConfirmation) {
return false;
}
await onboardActions.retire();
await retirementSuccessfulDialog();
return true;
};
export default retireAction;