-
Notifications
You must be signed in to change notification settings - Fork 569
/
Copy pathonChainConfig.js
127 lines (102 loc) · 3.53 KB
/
onChainConfig.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
import {FetchChain} from "bitsharesjs";
import {getConfigurationAsset} from "branding";
import asset_utils from "common/asset_utils";
const _fetchOnChainConfig = async function() {
let config = getConfigurationAsset();
if (!config.symbol) {
return {};
}
const assets = [await FetchChain("getAsset", config.symbol)];
let onChainConfig = {};
assets.forEach(asset => {
if (!asset) {
return;
}
try {
asset = asset.toJS();
let notification = asset_utils.parseDescription(
asset.options.description
);
if (!!notification.main) {
notification = notification.main.split(config.explanation);
if (notification.length > 1 && !!notification[1]) {
let _onChainConfig = JSON.parse(notification[1]);
onChainConfig = Object.assign(
onChainConfig,
_onChainConfig
);
}
}
} catch (err) {
console.error(
"JSON payload could not be parsed from asset description " +
asset.symbol,
asset
);
}
});
return onChainConfig;
};
const getNotifications = async function() {
const onChainConfig = await _fetchOnChainConfig();
if (!onChainConfig.notifications) {
return [];
}
let notificationList = [];
onChainConfig.notifications.forEach(item => {
notificationList.push(item);
});
return notificationList;
};
const getPredictionMarketIssuers = async function() {
const onChainConfig = await _fetchOnChainConfig();
return onChainConfig.predictionMarketIssuers || [];
};
const isGatewayTemporarilyDisabled = async function(gatewayKey) {
// map of all known gateways with additional values
// e.g. {OPEN: {enabled: true}}
const onChainConfig = await _fetchOnChainConfig();
if (!onChainConfig.gateways) return false;
if (!onChainConfig.gateways[gatewayKey]) return false;
if (onChainConfig.gateways[gatewayKey].enabled === false) return true;
return false;
};
const getGatewayComment = async function(gatewayKey) {
// map of all known gateways with additional values
// e.g. {OPEN: {enabled: true}}
const onChainConfig = await _fetchOnChainConfig();
if (!onChainConfig.gateways) return null;
if (!onChainConfig.gateways[gatewayKey]) return null;
if (!onChainConfig.gateways[gatewayKey].comment) return null;
return onChainConfig.gateways[gatewayKey].comment;
};
const getGatewayConfig = async function(gatewayKey) {
// map of all known gateways with additional values
// e.g. {OPEN: {enabled: true}}
const onChainConfig = await _fetchOnChainConfig();
if (!onChainConfig.gateways) return null;
if (!gatewayKey) {
return onChainConfig.gateways;
}
if (!onChainConfig.gateways[gatewayKey]) return null;
return onChainConfig.gateways[gatewayKey];
};
const getBlacklists = async function() {
const onChainConfig = await _fetchOnChainConfig();
if (!onChainConfig.blacklists) return {};
return onChainConfig.blacklists;
};
const getOnChainConfig = async function() {
const onChainConfig = await _fetchOnChainConfig();
if (!onChainConfig) return {};
return onChainConfig;
};
export {
getNotifications,
getPredictionMarketIssuers,
isGatewayTemporarilyDisabled,
getGatewayComment,
getGatewayConfig,
getBlacklists,
getOnChainConfig
};