@stokr/components-library 2.0.0-beta.26 → 2.0.0-beta.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/globalVariables.js +23 -2
- package/dist/context/Auth.js +13 -0
- package/dist/context/AuthContext.js +33 -29
- package/dist/firebase-config.js +1 -1
- package/dist/index.js +11 -0
- package/dist/utils/check-sale-time-left.js +120 -0
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.walletTypes = exports.platformURL = exports.platformDomain = void 0;
|
|
6
|
+
exports.walletTypes = exports.platformURL = exports.platformDomain = exports.ProjectTypes = exports.ProjectStatus = exports.ProjectStates = void 0;
|
|
7
7
|
var platformDomain = process.env.REACT_APP_WEBSITE_DOMAIN;
|
|
8
8
|
exports.platformDomain = platformDomain;
|
|
9
9
|
var platformURL = 'https://' + platformDomain;
|
|
@@ -13,4 +13,25 @@ var walletTypes = {
|
|
|
13
13
|
ALGORAND: 'algorand',
|
|
14
14
|
ETHEREUM: 'ethereum'
|
|
15
15
|
};
|
|
16
|
-
exports.walletTypes = walletTypes;
|
|
16
|
+
exports.walletTypes = walletTypes;
|
|
17
|
+
var ProjectTypes = {
|
|
18
|
+
FUND: 'fund',
|
|
19
|
+
COMPANY: 'company',
|
|
20
|
+
TRANCHES: 'tranches'
|
|
21
|
+
};
|
|
22
|
+
exports.ProjectTypes = ProjectTypes;
|
|
23
|
+
var ProjectStatus = {
|
|
24
|
+
ACTIVE: 'Active',
|
|
25
|
+
INACTIVE: 'Inactive',
|
|
26
|
+
ON_HOLD: 'On_hold'
|
|
27
|
+
};
|
|
28
|
+
exports.ProjectStatus = ProjectStatus;
|
|
29
|
+
var ProjectStates = {
|
|
30
|
+
ON_HOLD: 'ON HOLD',
|
|
31
|
+
LIVE: 'LIVE',
|
|
32
|
+
OPEN: 'OPEN',
|
|
33
|
+
CLOSED: 'CLOSED',
|
|
34
|
+
CLOSED_SUCCESSFULLY: 'CLOSED SUCCESSFULLY',
|
|
35
|
+
UPCOMING: 'UPCOMING'
|
|
36
|
+
};
|
|
37
|
+
exports.ProjectStates = ProjectStates;
|
package/dist/context/Auth.js
CHANGED
|
@@ -159,6 +159,19 @@ var Auth = /*#__PURE__*/function () {
|
|
|
159
159
|
});
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
|
+
}, {
|
|
163
|
+
key: "signInWithToken",
|
|
164
|
+
value: function signInWithToken(token) {
|
|
165
|
+
return new Promise(function (resolve, reject) {
|
|
166
|
+
(0, _auth.signInWithCustomToken)(_firebaseConfig.auth, token).then(function (userCredential) {
|
|
167
|
+
// Signed in
|
|
168
|
+
var user = userCredential.user;
|
|
169
|
+
resolve(user);
|
|
170
|
+
}).catch(function (error) {
|
|
171
|
+
reject(error);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
|
162
175
|
}, {
|
|
163
176
|
key: "updateUserPassword",
|
|
164
177
|
value: function updateUserPassword(user, newPassword) {
|
|
@@ -69,7 +69,7 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
69
69
|
});
|
|
70
70
|
_defineProperty(_assertThisInitialized(_this), "loginUser", /*#__PURE__*/function () {
|
|
71
71
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(email, password) {
|
|
72
|
-
var user, idToken
|
|
72
|
+
var user, idToken;
|
|
73
73
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
74
74
|
while (1) switch (_context.prev = _context.next) {
|
|
75
75
|
case 0:
|
|
@@ -84,50 +84,49 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
84
84
|
case 7:
|
|
85
85
|
idToken = _context.sent;
|
|
86
86
|
_Auth.default.setAccessToken(user.accessToken);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
console.log('🚀 ~ sessionLogin:', sessionLogin);
|
|
87
|
+
|
|
88
|
+
// const sessionLogin = await fetchData('auth/session-login', {
|
|
89
|
+
// idToken,
|
|
90
|
+
// })
|
|
91
|
+
// console.log('🚀 ~ sessionLogin:', sessionLogin)
|
|
92
|
+
|
|
94
93
|
_this.setState({
|
|
95
94
|
firebaseUser: user,
|
|
96
95
|
isFetchingUser: false
|
|
97
96
|
});
|
|
98
97
|
//if you need user immediatly
|
|
99
98
|
return _context.abrupt("return", user);
|
|
100
|
-
case
|
|
101
|
-
_context.prev =
|
|
99
|
+
case 13:
|
|
100
|
+
_context.prev = 13;
|
|
102
101
|
_context.t0 = _context["catch"](0);
|
|
103
102
|
console.log('🚀 ~ file: AuthContext.js:56 ~ error:', _context.t0);
|
|
104
103
|
_context.t1 = _context.t0.code;
|
|
105
|
-
_context.next = _context.t1 === 'auth/multi-factor-auth-required' ?
|
|
104
|
+
_context.next = _context.t1 === 'auth/multi-factor-auth-required' ? 19 : _context.t1 === 'auth/requires-recent-login' ? 21 : _context.t1 === 'auth/invalid-login-credentials' ? 23 : 25;
|
|
106
105
|
break;
|
|
107
|
-
case
|
|
106
|
+
case 19:
|
|
108
107
|
// Initiate your second factor sign-in flow. (See next step.)
|
|
109
108
|
_this.setState({
|
|
110
109
|
waitingFor2fa: true,
|
|
111
110
|
firebaseError: _context.t0
|
|
112
111
|
});
|
|
113
112
|
throw _context.t0;
|
|
114
|
-
case
|
|
113
|
+
case 21:
|
|
115
114
|
// The user's last sign-in time does not meet the security threshold.
|
|
116
115
|
_this.logoutUser();
|
|
117
|
-
return _context.abrupt("break",
|
|
118
|
-
case
|
|
116
|
+
return _context.abrupt("break", 28);
|
|
117
|
+
case 23:
|
|
119
118
|
_context.t0.message = 'The credentials are not correct. Try again?';
|
|
120
119
|
throw _context.t0;
|
|
121
|
-
case
|
|
120
|
+
case 25:
|
|
122
121
|
console.log({
|
|
123
122
|
error: _context.t0
|
|
124
123
|
}); // Handle other errors, such as wrong passwords.
|
|
125
124
|
throw _context.t0;
|
|
126
|
-
case
|
|
125
|
+
case 28:
|
|
127
126
|
case "end":
|
|
128
127
|
return _context.stop();
|
|
129
128
|
}
|
|
130
|
-
}, _callee, null, [[0,
|
|
129
|
+
}, _callee, null, [[0, 13]]);
|
|
131
130
|
}));
|
|
132
131
|
return function (_x, _x2) {
|
|
133
132
|
return _ref.apply(this, arguments);
|
|
@@ -349,9 +348,7 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
349
348
|
(0, _auth.signOut)(_firebaseConfig.auth).then(function () {
|
|
350
349
|
console.log('logged out');
|
|
351
350
|
});
|
|
352
|
-
|
|
353
|
-
return (0, _fetchData.default)('auth/session-logout');
|
|
354
|
-
case 4:
|
|
351
|
+
// await fetchData('auth/session-logout')
|
|
355
352
|
_Auth.default.logout();
|
|
356
353
|
delete _axios.default.defaults.headers.common.Authorization;
|
|
357
354
|
_this.setUser(null);
|
|
@@ -363,7 +360,7 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
363
360
|
if (redirect) {
|
|
364
361
|
window.location.href = "https://".concat(process.env.REACT_APP_WEBSITE_DOMAIN);
|
|
365
362
|
}
|
|
366
|
-
case
|
|
363
|
+
case 7:
|
|
367
364
|
case "end":
|
|
368
365
|
return _context7.stop();
|
|
369
366
|
}
|
|
@@ -384,6 +381,8 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
384
381
|
customValidateGetUser,
|
|
385
382
|
result,
|
|
386
383
|
firebaseUser,
|
|
384
|
+
_yield$fetchData,
|
|
385
|
+
customToken,
|
|
387
386
|
user,
|
|
388
387
|
userAvatar,
|
|
389
388
|
_args8 = arguments;
|
|
@@ -411,14 +410,19 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
411
410
|
result = _context8.sent;
|
|
412
411
|
firebaseUser = _this.state.firebaseUser;
|
|
413
412
|
if (firebaseUser) {
|
|
414
|
-
_context8.next =
|
|
413
|
+
_context8.next = 19;
|
|
415
414
|
break;
|
|
416
415
|
}
|
|
417
416
|
_context8.next = 14;
|
|
418
|
-
return
|
|
417
|
+
return (0, _fetchData.default)('auth/get-custom-token');
|
|
419
418
|
case 14:
|
|
419
|
+
_yield$fetchData = _context8.sent;
|
|
420
|
+
customToken = _yield$fetchData.customToken;
|
|
421
|
+
_context8.next = 18;
|
|
422
|
+
return _Auth.default.signInWithToken(customToken);
|
|
423
|
+
case 18:
|
|
420
424
|
firebaseUser = _context8.sent;
|
|
421
|
-
case
|
|
425
|
+
case 19:
|
|
422
426
|
//merge firebaseUser and our user object
|
|
423
427
|
user = _this.patchUserObject(result.user, firebaseUser);
|
|
424
428
|
console.log('🚀 ~ file: AuthContext.js:259 ~ user:', user);
|
|
@@ -439,19 +443,19 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
439
443
|
|
|
440
444
|
//if you need user info immediately after call (before setState is executed), you can use this
|
|
441
445
|
return _context8.abrupt("return", user);
|
|
442
|
-
case
|
|
443
|
-
_context8.prev =
|
|
446
|
+
case 31:
|
|
447
|
+
_context8.prev = 31;
|
|
444
448
|
_context8.t0 = _context8["catch"](6);
|
|
445
449
|
_this.setState({
|
|
446
450
|
isFetchingUser: false
|
|
447
451
|
});
|
|
448
452
|
console.log("Error in getUser: ".concat(_context8.t0));
|
|
449
453
|
throw _context8.t0;
|
|
450
|
-
case
|
|
454
|
+
case 36:
|
|
451
455
|
case "end":
|
|
452
456
|
return _context8.stop();
|
|
453
457
|
}
|
|
454
|
-
}, _callee8, null, [[6,
|
|
458
|
+
}, _callee8, null, [[6, 31]]);
|
|
455
459
|
})));
|
|
456
460
|
_defineProperty(_assertThisInitialized(_this), "checkUserPhoto", function (avatar) {
|
|
457
461
|
try {
|
package/dist/firebase-config.js
CHANGED
|
@@ -21,7 +21,7 @@ var app = (0, _app.initializeApp)(firebaseConfig);
|
|
|
21
21
|
|
|
22
22
|
// Initialize Firebase Authentication and get a reference to the service
|
|
23
23
|
var auth = (0, _auth.getAuth)(app);
|
|
24
|
-
//setPersistence(auth, inMemoryPersistence)
|
|
25
24
|
exports.auth = auth;
|
|
25
|
+
(0, _auth.setPersistence)(auth, _auth.inMemoryPersistence);
|
|
26
26
|
var _default = app;
|
|
27
27
|
exports.default = _default;
|
package/dist/index.js
CHANGED
|
@@ -1081,6 +1081,17 @@ Object.keys(_km_ify).forEach(function (key) {
|
|
|
1081
1081
|
}
|
|
1082
1082
|
});
|
|
1083
1083
|
});
|
|
1084
|
+
var _checkSaleTimeLeft = require("./utils/check-sale-time-left");
|
|
1085
|
+
Object.keys(_checkSaleTimeLeft).forEach(function (key) {
|
|
1086
|
+
if (key === "default" || key === "__esModule") return;
|
|
1087
|
+
if (key in exports && exports[key] === _checkSaleTimeLeft[key]) return;
|
|
1088
|
+
Object.defineProperty(exports, key, {
|
|
1089
|
+
enumerable: true,
|
|
1090
|
+
get: function get() {
|
|
1091
|
+
return _checkSaleTimeLeft[key];
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1094
|
+
});
|
|
1084
1095
|
var _FA = require("./components/2FA");
|
|
1085
1096
|
Object.keys(_FA).forEach(function (key) {
|
|
1086
1097
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.checkSaleTimeLeft = void 0;
|
|
7
|
+
var _globalVariables = require("../constants/globalVariables");
|
|
8
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
+
var getTimeLeft = function getTimeLeft(endTime) {
|
|
15
|
+
var now = new Date();
|
|
16
|
+
var oneDay = 1000 * 60 * 60 * 24;
|
|
17
|
+
var timeLeft = (endTime - now) / oneDay;
|
|
18
|
+
if (timeLeft >= 1) {
|
|
19
|
+
// Equal or more than 24h
|
|
20
|
+
return {
|
|
21
|
+
time: Math.round(timeLeft),
|
|
22
|
+
text: 'DAYS'
|
|
23
|
+
};
|
|
24
|
+
} else if (timeLeft * 24 >= 1) {
|
|
25
|
+
// Less than 24h
|
|
26
|
+
return {
|
|
27
|
+
time: Math.round(timeLeft * 24),
|
|
28
|
+
text: 'HOURS'
|
|
29
|
+
};
|
|
30
|
+
} else if (timeLeft * 24 * 60 >= 1) {
|
|
31
|
+
return {
|
|
32
|
+
time: Math.round(timeLeft * 24 * 60),
|
|
33
|
+
text: 'MINS'
|
|
34
|
+
};
|
|
35
|
+
} else {
|
|
36
|
+
return {
|
|
37
|
+
text: 'DAYS'
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var checkSaleTimeLeft = function checkSaleTimeLeft(project) {
|
|
42
|
+
var openingTime = project.openingTime,
|
|
43
|
+
closingTime = project.closingTime,
|
|
44
|
+
isOpen = project.isOpen,
|
|
45
|
+
hasClosed = project.hasClosed,
|
|
46
|
+
type = project.type,
|
|
47
|
+
sales = project.sales;
|
|
48
|
+
var timeLeftData = {
|
|
49
|
+
openingTime: openingTime,
|
|
50
|
+
closingTime: closingTime,
|
|
51
|
+
isOpen: isOpen,
|
|
52
|
+
hasClosed: hasClosed
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
//for the tranche project we check the current tranche status
|
|
56
|
+
if (type === _globalVariables.ProjectTypes.TRANCHES) {
|
|
57
|
+
var currentTranche = sales === null || sales === void 0 ? void 0 : sales.find(function (x) {
|
|
58
|
+
return x.isVariable;
|
|
59
|
+
});
|
|
60
|
+
var today = Date.now();
|
|
61
|
+
if (currentTranche) {
|
|
62
|
+
//if we have variable tranche we set opening and closing date of tranche
|
|
63
|
+
timeLeftData.openingTime = currentTranche.startDate;
|
|
64
|
+
timeLeftData.closingTime = currentTranche.endDate;
|
|
65
|
+
if (today < new Date(currentTranche.endDate)) {
|
|
66
|
+
timeLeftData.isOpen = true;
|
|
67
|
+
timeLeftData.hasClosed = false;
|
|
68
|
+
} else if (today > new Date(currentTranche.endDate)) {
|
|
69
|
+
timeLeftData.hasClosed = true;
|
|
70
|
+
timeLeftData.isOpen = false;
|
|
71
|
+
} else {
|
|
72
|
+
timeLeftData.isOpen = false;
|
|
73
|
+
timeLeftData.hasClosed = false;
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
//upcoming state where we don't have variable sale
|
|
77
|
+
//we use opening and closing time of project
|
|
78
|
+
timeLeftData = _objectSpread(_objectSpread({}, timeLeftData), {}, {
|
|
79
|
+
isOpen: false,
|
|
80
|
+
hasClosed: false
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
console.log('🚀 ~ file: TrendingSlide.jsx:772 ~ timeLeftData:', timeLeftData, project.name, calculateTimeLeft(timeLeftData));
|
|
84
|
+
}
|
|
85
|
+
return calculateTimeLeft(timeLeftData);
|
|
86
|
+
};
|
|
87
|
+
exports.checkSaleTimeLeft = checkSaleTimeLeft;
|
|
88
|
+
var calculateTimeLeft = function calculateTimeLeft(timeLeftData) {
|
|
89
|
+
var _timeLeftData$opening = timeLeftData.openingTime,
|
|
90
|
+
openingTime = _timeLeftData$opening === void 0 ? '' : _timeLeftData$opening,
|
|
91
|
+
_timeLeftData$closing = timeLeftData.closingTime,
|
|
92
|
+
closingTime = _timeLeftData$closing === void 0 ? '' : _timeLeftData$closing,
|
|
93
|
+
isOpen = timeLeftData.isOpen,
|
|
94
|
+
hasClosed = timeLeftData.hasClosed;
|
|
95
|
+
if (!timeLeftData || !isOpen && !hasClosed) {
|
|
96
|
+
// Before sale
|
|
97
|
+
var startingDate = new Date(openingTime);
|
|
98
|
+
var timeLeft = getTimeLeft(startingDate);
|
|
99
|
+
return {
|
|
100
|
+
daysLeft: timeLeft.time,
|
|
101
|
+
daysLeftText: "".concat(timeLeft.text, " UNTIL START")
|
|
102
|
+
};
|
|
103
|
+
} else if (isOpen) {
|
|
104
|
+
// During sale
|
|
105
|
+
var endingDate = new Date(closingTime);
|
|
106
|
+
var _timeLeft = getTimeLeft(endingDate);
|
|
107
|
+
return {
|
|
108
|
+
daysLeft: _timeLeft.time,
|
|
109
|
+
daysLeftText: "".concat(_timeLeft.text, " LEFT")
|
|
110
|
+
};
|
|
111
|
+
} else {
|
|
112
|
+
// After sale
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
daysLeftText: 'FUNDING CLOSED'
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
var _default = checkSaleTimeLeft;
|
|
120
|
+
exports.default = _default;
|