· 4 years ago · May 28, 2021, 12:56 AM
1/* eslint-disable */
2import React from 'react';
3import { withRouter } from 'react-router-dom';
4import { connect } from 'react-redux';
5import FullLayout from '../../components/layouts/fulllayout.jsx';
6import { set_selected_vault, set_logout_session, set_shared_vault_details } from '../../actions/registration.actions';
7import moment from 'moment';
8import { getFormattedNumber } from '../../utils';
9import { toast } from "react-toastify";
10import { isEmail } from 'validator';
11
12import helpers from '../helpers/util';
13import ConfigSettingsSuccessMessage from '../../views/msgs/ConfigSettingsSuccessMessage.jsx';
14import ConfigWhitelistSuccessMessage from '../../views/msgs/ConfigWhitelistSuccessMessage.jsx';
15import WhitelistSettingsErrorMessage from '../../views/msgs/WhitelistSettingsErrorMessage.jsx'
16import { VaultCreatedSuccessMessage, TokenCreatedSuccessMessage, WithdrawSuccessMessage, WithdrawFailMessage, AddTokenFailMessage } from '../../views/toastpopups/vaultCreatedPopup';
17import numio, { call } from "numio-cdn";
18import axios from "axios";
19
20const _ = require('loadsh')
21const message = require('../../constants/messages');
22const scientificToDecimal = require('scientific-to-decimal');
23
24const availableCoins = [
25 {
26 name: 'ETH',
27 USDPRICE: 'ETHUSD',
28 BTCPRICE: 'ETHBTC'
29 },
30 {
31 name: 'HYDRO',
32 USDPRICE: 'HYDROUSD',
33 BTCPRICE: 'HYDROBTC'
34 },
35 {
36 name: 'USDC',
37 USDPRICE: 'USDCUSD',
38 BTCPRICE: 'USDCBTC'
39 },
40 {
41 name: 'PHNX',
42 USDPRICE: 'PHNXUSD',
43 BTCPRICE: 'PHNXBTC'
44 }
45]
46
47const vaultData = {
48 _id: "",
49 balances: "",
50 currency: "",
51 name: "",
52 address: "",
53 allAccepted: false,
54 type: "",
55 label: "",
56 value: ""
57}
58
59class _DashboardContainer extends React.Component {
60
61 constructor() {
62 super();
63
64 this.onFilterTransactions = this.onFilterTransactions.bind(this);
65 this.updateNotificationReadStatus = this.updateNotificationReadStatus.bind(this);
66 this.getFilteredVaults = this.getFilteredVaults.bind(this);
67 this.handleDashboardVaultSelect = this.handleDashboardVaultSelect.bind(this);
68 this.withdrawNumioIdentityAuth = this.withdrawNumioIdentityAuth.bind(this);
69
70
71 this.state = {
72 isConfigOpen: false,
73 isConfigFade: false,
74 isDeadManSwitchOpen: false,
75 vaultNameError: false,
76 cryptoAssetError: false,
77 isDeadManSwitchFade: false,
78 isVaultLoading: false,
79 isMaxDailyTxUnlimited: false,
80 isMaxDailyAmountUnlimited: false,
81 isMaxTxHourUnlimited: false,
82 vaultName: '',
83 isNotified: false,
84 qrUrl: undefined,
85 qrLoader: false,
86 cryptoAsset: '',
87 tokenAsset: '',
88 tokenAssetError: false,
89 vaultType: 'single',
90 maxDailyTx: 0,
91 allTempTransactions: [],
92 maxTxHour: 0,
93 maxDailyAmount: 0,
94 email: undefined,
95 isOpenAddTokenModal: false,
96 isOverview: false,
97 isTxnsLoading: false,
98 first_name: undefined,
99 deadmanAddress: undefined,
100 allNotifications: [],
101 filerNotifcations: [],
102 allVaults: [],
103 filterAllVaults: [],
104 last_name: undefined,
105 secondary_email: undefined,
106 tfa_type: undefined,
107 auth_type: undefined,
108 withdrawAmount_error: undefined,
109 withdrawReceiver_error: undefined,
110 vaults: [],
111 optionVaults: [],
112 tokensList: [],
113 userID: undefined,
114 isLoadingCryptoAsset: false,
115 headerVaultSelect: undefined,
116 modal: false,
117 fade: false,
118 isOpenAuthForCreateSharedVault: false,
119 updateWhitelistUserAddress: undefined,
120 updateWhitelistUserEmail: undefined,
121 updateWhitelistUserName: undefined,
122 coSignerAuthModal: false,
123 userImageData: undefined,
124 coSignerAuthFade: false,
125 isCoSignerWarningPopupEnable: false,
126 isCoSignerWarningPopupModal: false,
127 isCoSignerWarningPopupFade: false,
128 isCoSignerSummaryOnePopupEnable: false,
129 isCoSignerSummaryOnePopupModal: false,
130 isCoSignerSummaryOnePopupFade: false,
131 isUpdateWhitelistAvailable: false,
132 isWithdrawVerified: false,
133 isLoading: false,
134 transactionHistoryFlag: 'all',
135 currentVaultType: 'all',
136 graphHistoryFlag: 'week',
137 configVaultSelect: undefined,
138 allTransactionHistory: [],
139 filterTransactionHistory: [],
140 isLoadingBalance: false,
141 twoFA_error: undefined,
142 isCopied: false,
143 token: undefined,
144 vaultsBalance: [],
145 totalVaultBalance: 0,
146 totalBalance: 0,
147 selectedVault: undefined,
148 isWithdrawIntiOpen: true,
149 isWithdrawIntiFade: true,
150 isVerifiedNumio: false,
151 isShowDeadManSwitch: false,
152 isWithdrawNextFade: false,
153 depositVaultSelect: undefined,
154 isWithdrawNextOpen: false,
155 isOpenSendaPaymentModal: false,
156 isOpenAddRecipientModal: false,
157 isOpenSuccessModal: false,
158 twoFA_error_addVault: undefined,
159 withdrawReceiver: '',
160 withdrawVaultSelect: undefined,
161 withdrawAmount: '',
162 withdrawSymbol: undefined,
163 withdrawLoading: false,
164 withdrawError: undefined,
165
166 isDepositNextOpen: false,
167 isDepositNextFade: false,
168 isDepositIntiFade: true,
169 isDepositIntiOpen: true,
170 whitelistUserName: undefined,
171 isNextWhitelistUserAllowed: true,
172 isDeadManSwitchWalletAddressEnable: false,
173 whitelistUserEmail: undefined,
174 isNotifyUser: false,
175 whitelistUserName_error: undefined,
176 whitelistUserEmail_error: undefined,
177 whitelistUserAddress_error: undefined,
178 whitelistUserAddress: undefined,
179 whiteListUsersCount: 0,
180 vaultNameError_text: undefined,
181 cryptoAssetError_text: undefined,
182 whiteListUsersData: [],
183 currentWhiteListUser: {},
184 coSignerCount: 0,
185 authmodal: false,
186 authfade: false,
187
188 rangeFilters: [
189 {
190 label: 'Year',
191 value: 'year'
192 },
193 {
194 label: 'Month',
195 value: 'month'
196 },
197 {
198 label: 'Day',
199 value: 'day'
200 }
201 ],
202 selectedRangeFilter: undefined,
203 sortFilters: [
204 {
205 label: 'Lowest Balance',
206 value: 'lowestBalance'
207 },
208 {
209 label: 'Highest Balance',
210 value: 'highestBalance'
211 }
212 ],
213 graphData: [],
214 filterGraphData: [],
215 graphDataWithLabels: [],
216 ETHBTC: 0,
217 ETHUSD: 0,
218 HYDROBTC: 0,
219 HYDROUSD: 0,
220 PHNXBTC: 0,
221 PHNXUSD: 0,
222 USDCBTC: 0,
223 USDCUSD: 0,
224 gainLossValue: 0,
225 gainLossPercentage: 0,
226 selectedSortFilter: undefined,
227 startDate: new Date(),
228 endDate: new Date(),
229 withdrawVaultSelect_error: undefined,
230 depositVaultSelect_error: undefined,
231 sharedVaultData_vaultName: '',
232 sharedVaultData_cryptoAsset: '',
233 sharedVaultData_maxSigner: 2,
234 sharedVaultData_currentSignerCount: 1,
235 isConfigScreenShow: false,
236 sharedVaultData_coSignerData: [],
237
238 sharedVaultData_currentCoSignerEmail: undefined,
239 deadManTime: 0,
240 selectdDeadManTimeFrame: {
241 label: 'day',
242 value: 'day'
243 },
244 deadManTimeFrame: [
245 {
246 label: 'day',
247 value: 'day'
248 },
249 {
250 label: 'month',
251 value: 'month'
252 },
253 {
254 label: 'year',
255 value: 'year'
256 }
257 ]
258 }
259 }
260 _isMounted = false;
261
262 static getDerivedStateFromProps(nextProps, prevState) {
263 return true
264 }
265
266 componentDidMount = async () => {
267 this._isMounted = true;
268
269 /**
270 * check is token expired or not
271 */
272 this.checkIsSessionActive();
273 this.getUserAuthType();
274 const userDetails = this.props.client_manager.auth.getUserDetails();
275 if ((userDetails && userDetails.user_vault_name) && (this.props.match.path !== '/vaults')) {
276 this.setState({
277 headerVaultSelect: {
278 _id: userDetails.user_vault_id,
279 currency: userDetails.user_vault_currency,
280 name: userDetails.user_vault_name,
281 type: userDetails.vault_type,
282 address: userDetails.user_vault_address,
283 label: `${userDetails.user_vault_name} - ${userDetails.vault_balances ? userDetails.vault_balances : 0} ${userDetails.user_vault_currency ? userDetails.user_vault_currency : 'ETH'}`,
284 value: userDetails.user_vault_address
285 },
286 configVaultSelect: {
287
288 _id: userDetails.user_vault_id,
289 currency: userDetails.user_vault_currency,
290 name: userDetails.user_vault_name,
291 type: userDetails.vault_type,
292 address: userDetails.user_vault_address,
293 label: `${userDetails.user_vault_name} - ${userDetails.vault_balances ? userDetails.vault_balances : 0} ${userDetails.user_vault_currency ? userDetails.user_vault_currency : 'ETH'}`,
294 value: userDetails.user_vault_address
295
296 }
297 })
298 }
299
300 if (this.props.match.path === '/settings') {
301 const configVaultSelect = {
302 _id: userDetails.user_vault_id,
303 currency: userDetails.user_vault_currency,
304 name: userDetails.user_vault_name,
305 type: userDetails.vault_type,
306 address: userDetails.user_vault_address,
307 label: `${userDetails.user_vault_name} - ${userDetails.vault_balances ? userDetails.vault_balances : 0} ${userDetails.user_vault_currency ? userDetails.user_vault_currency : 'ETH'}`,
308 value: userDetails.user_vault_address
309
310 }
311 this.handleConfigVaultSelect(configVaultSelect)
312 this.getUserInfo();
313 this.updateVaultList(true)
314 } else {
315
316 this.getCurrentUsdValue()
317 this.getCurrentBTCValue();
318 /**
319 * Clear data on allVaults route
320 */
321 if (this.props && this.props.vaultData && this.props.vaultData.address) {
322 this.setState({
323 withdrawVaultSelect: this.props.vaultData
324 })
325 }
326 if (this.props.match.path === '/vaults') {
327 this.props.client_manager.auth.saveUserSelectedVault(vaultData);
328 await this.props.dispatch(set_logout_session());
329 }
330 this.getUserInfo();
331 this.getAllTokens();
332 const userDeatils = this.props.client_manager.auth.getUserDetails();
333 this.updateVaultList(true)
334 if (this.props.vaultData || (userDeatils && userDeatils.user_vault_address)) {
335 if ((this.props.vaultData && this.props.vaultData.type === 'shared') || (userDeatils.vault_type === 'shared')) {
336 this.getSharedVaultData()
337 } else {
338 this.getSingleVaultData()
339 }
340 } else {
341 /**
342 * Get All vaults balance
343 */
344 this.getAllVaultBalance();
345 /**
346 * Get All Graph Data
347 */
348 this.getAllGraphData();
349 /**
350 * Get All Txns History
351 */
352 this.getAllTxnsHistory();
353
354 /**
355 * Get All Vaults balance
356 */
357 this.getTotalBalance();
358 }
359 }
360
361 }
362
363 componentWillUnmount() {
364 this._isMounted = false;
365 }
366
367 checkIsSessionActive = () => {
368 const isTokenAvailable = localStorage.getItem("access_token");
369 const header = this.props.client_manager.auth.getHeader();
370 if (isTokenAvailable) {
371 this.props.client_manager.service.getNotificationAPI(
372 header,
373 (data) => {
374 return true;
375 },
376 (error) => {
377 if (error && error.response && error.response.status && error.response.status === 401) {
378 this.props.history.push('/login')
379 } else {
380 return true
381 }
382 });
383 } else {
384 this.props.history.push('/login')
385 }
386 }
387
388 /**
389 * getUserAuthType
390 */
391 getUserAuthType = async () => {
392 const isTokenAvailable = localStorage.getItem("access_token");
393 const email = localStorage.getItem("user_email");
394 const header = this.props.client_manager.auth.getHeader();
395
396 if (isTokenAvailable && email) {
397
398 this.props.client_manager.service.getUserAuthType(
399 header,
400 email,
401 (data) => {
402 this.setState({
403 auth_type: data.data.auth_type
404 })
405 },
406 (error) => {
407 if (error && error.response && error.response.status && error.response.status === 401) {
408 this.props.history.push('/login')
409 } else {
410 return true
411 }
412 });
413 }
414 }
415
416 /**
417 * uploadPhotoChange
418 */
419
420 uploadPhotoChange = (file, res) => {
421 if (res && res.data && res.data.link) {
422 const imageURLPosition = res.data.link.split("profile/")
423 const image = `profile/${imageURLPosition[1]}`;
424 this.setState({
425 userImageData: image
426 })
427 }
428 }
429
430 intervalTime = 80000;
431
432 /**
433 * Set Interval to update the balance and trxns
434 */
435 timerId = setInterval(() => {
436
437 if (this.props.match.path === '/dashboard') {
438
439 /**
440 * Update Notification every 30 sec
441 */
442 const isTokenAvailable = localStorage.getItem("access_token");
443 if (isTokenAvailable && isTokenAvailable !== 'undefind') {
444 this.getVaultNotifications(false)
445
446 const userDeatils = this.props.client_manager.auth.getUserDetails();
447
448 if (this.props.vaultData || (userDeatils && ((userDeatils.user_vault_address !== "undefined") && ((userDeatils.user_vault_address !== null))))) {
449 if ((this.props.vaultData && this.props.vaultData.type === 'shared') || (userDeatils.vault_type === 'shared')) {
450 this.getSharedVaultsBalance(false, this.props.vaultData);
451 this.sharedVaultGraphData();
452 this.updateVaultList(true)
453 this.sharedVaultTxnsHistory();
454 this.getCurrentUsdValue()
455 this.getCurrentBTCValue();
456 } else {
457 this.graphData();
458 this.updateVaultList(true)
459 this.getTransactionHistory(false, this.props.vaultData)
460 this.getVaultsBalance(false, this.props.vaultData)
461 this.getCurrentUsdValue()
462 this.getCurrentBTCValue();
463 }
464 } else {
465 /**
466 * Get All Vaults balance
467 */
468 this.getTotalBalance();
469 /**
470 * Get All vaults balance
471 */
472 this.getAllVaultBalance();
473
474 /**
475 * Get All Txns History
476 */
477 this.getAllTxnsHistory();
478
479 this.getCurrentUsdValue()
480 this.getCurrentBTCValue();
481 this.getAllGraphData()
482 this.updateVaultList(false)
483 }
484 }
485 }
486 }, 80000);
487
488 /**
489 * Get current USD price with ETH
490 */
491 getCurrentUsdValue = () => {
492 const header = this.props.client_manager.auth.getHeader();
493 availableCoins.forEach((coinSymbol) => {
494 this.props.client_manager.service.getCurrentUsdValueByCoin(
495 header,
496 coinSymbol.name.toUpperCase(),
497 (data) => {
498 const dataPrice = (data && data.data && data.data.prices && data.data.prices.length > 0) ? data.data.prices[0] : 0;
499 this.setState({
500 [coinSymbol.USDPRICE]: dataPrice.price
501 })
502 },
503 (error) => {
504 this.setState({
505 [coinSymbol.USDPRICE]: 0
506 })
507 });
508 })
509 }
510
511 /**
512 * Get current BTC price with ETH
513 */
514 getCurrentBTCValue = () => {
515 const header = this.props.client_manager.auth.getHeader();
516 availableCoins.forEach((coinSymbol) => {
517 this.props.client_manager.service.getCurrentBTCValueByCoin(
518 header,
519 coinSymbol.name.toUpperCase(),
520 (data) => {
521 const dataPrice = (data && data.data && data.data.prices && data.data.prices.length > 0) ? data.data.prices[0] : 0;
522 this.setState({
523 [coinSymbol.BTCPRICE]: dataPrice.price
524 })
525 },
526 (error) => {
527 this.setState({
528 [coinSymbol.BTCPRICE]: 0
529 })
530 });
531 })
532 }
533 /**
534 * Update notificaiton status
535 */
536 updateNotificationReadStatus = (e, notifications) => {
537 const header = this.props.client_manager.auth.getHeader();
538 const { filerNotifcations, allNotifications } = this.state;
539
540 if (notifications.length > 0) {
541 notifications.forEach((notification) => {
542 if (!notification.isRead) {
543 const form = {
544 notification_id: notification._id
545 }
546 this.props.client_manager.service.updateNotificationStatus(
547 header,
548 form,
549 (data) => {
550
551 const newFilterNotifications = filerNotifcations.filter((thread) => thread._id !== notification._id)
552
553 const allNotificationsData = allNotifications.map((singleThread) => {
554 if (notification._id === singleThread._id) {
555 singleThread.isRead = true;
556 return singleThread;
557 } else {
558 return singleThread
559 }
560 })
561
562 this.setState({
563 allNotifications: allNotificationsData,
564 filerNotifcations: newFilterNotifications
565 })
566 },
567 (error) => {
568 if (error && error.response && error.response.status && error.response.status === 401) {
569 this.props.history.push('/login')
570 }
571
572 });
573 }
574 })
575 }
576 }
577 /**
578 * Get Notification data
579 */
580 getVaultNotifications = async (e) => {
581 if (e) {
582 e.preventDefault()
583 }
584
585 const header = this.props.client_manager.auth.getHeader();
586 const allNotifications = await helpers.getAllNotifications(this.props, header)
587
588 if (allNotifications.success && allNotifications.data && allNotifications.data.length > 0) {
589 let filerNotifcations = allNotifications.data.filter((notification) => notification.isRead !== true);
590 filerNotifcations = _.orderBy(filerNotifcations, ['createdAt'], ['desc']);
591 let allNotificationsFilterd = allNotifications.data;
592 allNotificationsFilterd = _.orderBy(allNotificationsFilterd, ['createdAt'], ['desc']);
593
594 this.setState({
595 allNotifications: allNotificationsFilterd,
596 filerNotifcations: filerNotifcations
597 })
598 } else {
599 this.setState({
600 allNotifications: [],
601 filerNotifcations: []
602 })
603 }
604
605 }
606 /**
607 * getAllVaultBalance for shared and single
608 */
609 getAllVaultBalance = async () => {
610 this.setState({
611 isVaultLoading: true
612 })
613 const header = this.props.client_manager.auth.getHeader();
614 const singleVaultBalance = await helpers.getSingleAllVaultBalance(this.props, header)
615 const sharedVaultBalance = await helpers.getSharedAllVaultBalance(this.props, header)
616 const newBalanceData = [...singleVaultBalance.data, ...sharedVaultBalance.data]
617
618 this.setState({
619 vaultsBalance: newBalanceData,
620 isVaultLoading: false
621 })
622 }
623 /**
624 * Get All Graph data for shared and single
625 */
626 getAllGraphData = async () => {
627 const filterType = this.state.graphHistoryFlag;
628 const header = this.props.client_manager.auth.getHeader();
629 const singleVaultGraph = await helpers.getSingleAllVaultGraph(this.props, header, filterType)
630 const newGraphData = [...singleVaultGraph.data]
631
632 this.setState({
633 graphData: newGraphData,
634 filterGraphData: newGraphData,
635 gainLossValue: singleVaultGraph.historyData ? singleVaultGraph.historyData.gainLoss : 0,
636 gainLossPercentage: singleVaultGraph.historyData ? singleVaultGraph.historyData.gainLossPercentage : 0
637 })
638 this.setGraphData(newGraphData)
639 }
640
641 /**
642 * Get All txns history for shared and single vaults
643 */
644 getAllTxnsHistory = async () => {
645 const header = this.props.client_manager.auth.getHeader();
646 const singleVaultTxn = await helpers.getSingleAllTxnsHistory(this.props, header)
647 const sharedVaultTxn = await helpers.getSharedAllTxnsHistory(this.props, header)
648
649 const newtxnsDataDeposite = [...singleVaultTxn.data.deposits, ...sharedVaultTxn.data.deposits]
650 const newtxnsDataWithdraw = [...singleVaultTxn.data.withdrawals, ...sharedVaultTxn.data.withdrawals]
651 const newtxnsData = {
652 deposits: newtxnsDataDeposite,
653 withdrawals: newtxnsDataWithdraw
654 }
655
656 this.updateTransactionHistory('all', newtxnsData)
657 }
658
659 getTotalBalance = async (vaultId, type) => {
660 const header = this.props.client_manager.auth.getHeader();
661 const totalVaultsBalance = await helpers.getAllVaultBalance(this.props, header, vaultId, type);
662 this.setState({
663 totalBalance: totalVaultsBalance.data
664 })
665 }
666
667 /**
668 * Get Shared Vault data
669 */
670 getSharedVaultData = (e, vaultData) => {
671 this.getSharedVaultsBalance(true, vaultData);
672 this.sharedVaultGraphData(e, vaultData);
673 this.sharedVaultTxnsHistory(e, vaultData);
674 this.getCurrentUsdValue()
675 this.getCurrentBTCValue();
676 }
677 /**
678 * Get Shared Vault Txns History
679 */
680 sharedVaultTxnsHistory = (e, vaultData) => {
681 const { transactionHistoryFlag } = this.state;
682
683 const header = this.props.client_manager.auth.getHeader();
684 const userDeatils = this.props.client_manager.auth.getUserDetails();
685
686 var vaultID = this.props.vaultData ? this.props.vaultData._id : userDeatils.user_vault_id;
687
688 if (vaultData) {
689 vaultID = vaultData._id
690 }
691
692 if (!vaultID) {
693 this.props.client_manager.service.getSharedAllVaultTxns(
694 header,
695 (data) => {
696 this.setState({
697 isTxnsLoading: false
698 })
699
700 this.updateTransactionHistory('all', data.historyData.transactions)
701 },
702 (error) => {
703 if (error && error.response && error.response.status && error.response.status === 401) {
704 this.props.history.push('/login')
705 }
706 this.setState({
707 isTxnsLoading: false
708 })
709 });
710 } else {
711 this.props.client_manager.service.getSharedSingleVaultTxns(
712 header,
713 vaultID,
714 transactionHistoryFlag,
715 (data) => {
716 this.setState({
717 isTxnsLoading: false
718 })
719 this.updateTransactionHistory(transactionHistoryFlag, data.historyData.transactions)
720 },
721 (error) => {
722 if (error && error.response && error.response.status && error.response.status === 401) {
723 this.props.history.push('/login')
724 }
725 this.setState({
726 isTxnsLoading: false
727 })
728 });
729 }
730 }
731 /**
732 * Get Txns Vault History for Single Vault
733 */
734 getSingleVaultData = (vaultData) => {
735 this.graphData(vaultData);
736 this.getTransactionHistory(true, vaultData)
737 this.getVaultsBalance(true, vaultData)
738 this.getCurrentUsdValue()
739 this.getCurrentBTCValue();
740 }
741 /**
742 * Get Transaction history on dashboard
743 */
744 getTransactionHistory = (isLoading, vaultData) => {
745 const { transactionHistoryFlag } = this.state;
746 this.setState({
747 isTxnsLoading: isLoading
748 })
749 const header = this.props.client_manager.auth.getHeader();
750 const userDeatils = this.props.client_manager.auth.getUserDetails();
751
752 var vaultID = this.props.vaultData ? this.props.vaultData._id : userDeatils.user_vault_id;
753
754 if (vaultData) {
755 vaultID = vaultData._id
756 }
757
758 if (!vaultID) {
759 // if (this.state.vaults.length > 0) {
760 this.props.client_manager.service.getAllVaultsTxnsHistory(
761 header,
762 (data) => {
763 this.setState({
764 isTxnsLoading: false
765 })
766
767 this.updateTransactionHistory('all', data.historyData.transactions)
768 },
769 (error) => {
770 this.setState({
771 isTxnsLoading: false
772 })
773 });
774 // }
775 } else {
776 this.props.client_manager.service.getTransactionHistory(
777 header,
778 vaultID,
779 transactionHistoryFlag,
780 (data) => {
781 this.setState({
782 isTxnsLoading: false
783 })
784 this.updateTransactionHistory(transactionHistoryFlag, data.historyData.transactions)
785 },
786 (error) => {
787 this.setState({
788 isTxnsLoading: false
789 })
790 });
791 }
792 }
793
794 handleVaultName = e => {
795 const key = e.target.id
796 this.setState({
797 [key]: e.target.value,
798 vaultNameError: false
799 })
800 }
801
802 onSideBarChanged = async (value) => {
803 if (value === 'dashboard') {
804 this.props.client_manager.auth.saveUserSelectedVault(vaultData);
805 await this.props.dispatch(set_logout_session());
806 this.setState({
807 isOverview: !this.state.isOverview
808 })
809 /**
810 * Get All vaults balance
811 */
812 this.getAllVaultBalance();
813 /**
814 * Get All Graph Data
815 */
816 this.getAllGraphData();
817 /**
818 * Get All Txns History
819 */
820 this.getAllTxnsHistory();
821 /**
822 * Get All Vaults balance
823 */
824 this.getTotalBalance();
825 }
826 }
827 /**
828 * Shared Vault Graph Data
829 */
830 sharedVaultGraphData = (isLoading, vaultData) => {
831 const header = this.props.client_manager.auth.getHeader();
832 const userDeatils = this.props.client_manager.auth.getUserDetails();
833
834 let totalGainLossValue = 0;
835 let totalGainLossPercentage = 0;
836
837 var vaultID = this.props.vaultData ? this.props.vaultData._id : userDeatils.user_vault_id;
838 if (vaultData) {
839 vaultID = vaultData._id
840 }
841 const { graphHistoryFlag } = this.state;
842 if (vaultID) {
843 this.props.client_manager.service.getSingleSharedGraphData(
844 header,
845 vaultID,
846 graphHistoryFlag,
847 (data) => {
848
849 if (data.historyData) {
850 totalGainLossValue = parseFloat(data.historyData.gainLoss);
851 totalGainLossPercentage = parseFloat(data.historyData.gainLossPercentage);
852 }
853
854 this.setState({
855 graphData: data.data,
856 filterGraphData: data.data,
857 gainLossValue: totalGainLossValue,
858 gainLossPercentage: totalGainLossPercentage
859 })
860 this.setGraphData(data.data)
861 },
862 (error) => {
863 if (error && error.response && error.response.status && error.response.status === 401) {
864 this.props.history.push('/login')
865 }
866 });
867 } else {
868 this.props.client_manager.service.getSharedAllGraphData(
869 header,
870 graphHistoryFlag,
871 (data) => {
872
873 if (data.historyData) {
874 totalGainLossValue = parseFloat(data.historyData.gainLoss);
875 totalGainLossPercentage = parseFloat(data.historyData.gainLossPercentage);
876 }
877
878 this.setState({
879 graphData: data.data,
880 filterGraphData: data.data,
881 gainLossValue: totalGainLossValue,
882 gainLossPercentage: totalGainLossPercentage
883 })
884 this.setGraphData(data.data)
885 },
886 (error) => {
887 if (error && error.response && error.response.status && error.response.status === 401) {
888 this.props.history.push('/login')
889 }
890
891 });
892 }
893 }
894 /**
895 * graphData
896 */
897 graphData = (vaultData) => {
898 const header = this.props.client_manager.auth.getHeader();
899 const userDeatils = this.props.client_manager.auth.getUserDetails();
900
901 let totalGainLossValue = 0;
902 let totalGainLossPercentage = 0;
903
904 var vaultID = this.props.vaultData ? this.props.vaultData._id : userDeatils.user_vault_id;
905 if (vaultData) {
906 vaultID = vaultData._id
907 }
908 const { graphHistoryFlag } = this.state;
909
910 if ((this.props.vaultData && this.props.vaultData.type === 'shared') || (userDeatils.vault_type === 'shared')) {
911 if (!vaultData) {
912 this.sharedVaultGraphData();
913 } else {
914 if (vaultID) {
915 this.props.client_manager.service.getSingleGraphData(
916 header,
917 vaultID,
918 graphHistoryFlag,
919 (data) => {
920
921 if (data.historyData) {
922 totalGainLossValue = parseFloat(data.historyData.gainLoss);
923 totalGainLossPercentage = parseFloat(data.historyData.gainLossPercentage);
924 }
925
926 this.setState({
927 graphData: data.data,
928 filterGraphData: data.data,
929 gainLossValue: totalGainLossValue,
930 gainLossPercentage: totalGainLossPercentage
931 })
932 this.setGraphData(data.data)
933 },
934 (error) => {
935 });
936 } else {
937 this.props.client_manager.service.getAllGraphData(
938 header,
939 graphHistoryFlag,
940 (data) => {
941 if (data.historyData) {
942 totalGainLossValue = parseFloat(data.historyData.gainLoss);
943 totalGainLossPercentage = parseFloat(data.historyData.gainLossPercentage);
944 }
945 this.setState({
946 graphData: data.data,
947 filterGraphData: data.data,
948 gainLossValue: totalGainLossValue,
949 gainLossPercentage: totalGainLossPercentage
950 })
951 this.setGraphData(data.data)
952 },
953 (error) => {
954 });
955 }
956 }
957
958 } else {
959 if (vaultID) {
960 this.props.client_manager.service.getSingleGraphData(
961 header,
962 vaultID,
963 graphHistoryFlag,
964 (data) => {
965
966 if (data.historyData) {
967 totalGainLossValue = parseFloat(data.historyData.gainLoss);
968 totalGainLossPercentage = parseFloat(data.historyData.gainLossPercentage);
969 }
970
971 this.setState({
972 graphData: data.data,
973 filterGraphData: data.data,
974 gainLossValue: totalGainLossValue,
975 gainLossPercentage: totalGainLossPercentage
976 })
977 this.setGraphData(data.data)
978 },
979 (error) => {
980 });
981 } else {
982 this.props.client_manager.service.getAllGraphData(
983 header,
984 graphHistoryFlag,
985 (data) => {
986
987 if (data.historyData) {
988 totalGainLossValue = parseFloat(data.historyData.gainLoss);
989 totalGainLossPercentage = parseFloat(data.historyData.gainLossPercentage);
990 }
991
992 this.setState({
993 graphData: data.data,
994 filterGraphData: data.data,
995 gainLossValue: totalGainLossValue,
996 gainLossPercentage: totalGainLossPercentage
997 })
998
999 this.setGraphData(data.data)
1000 },
1001 (error) => {
1002 });
1003 }
1004 }
1005 }
1006
1007 getCurrentPrice = (currency) => {
1008 if (currency === 'HYDRO') {
1009 return {
1010 BTC: this.state.HYDROBTC ? this.state.HYDROBTC : 0,
1011 USD: this.state.HYDROUSD ? this.state.HYDROUSD : 0
1012 }
1013 } else if (currency === 'ETH') {
1014 return {
1015 BTC: this.state.ETHBTC ? this.state.ETHBTC : 0,
1016 USD: this.state.ETHUSD ? this.state.ETHUSD : 0
1017 }
1018 } else if (currency === 'USDC') {
1019 return {
1020 BTC: this.state.USDCBTC ? this.state.USDCBTC : 0,
1021 USD: this.state.USDCUSD ? this.state.USDCUSD : 0
1022 }
1023 } else if (currency === 'PHNX') {
1024 return {
1025 BTC: this.state.PHNXBTC ? this.state.PHNXBTC : 0,
1026 USD: this.state.PHNXUSD ? this.state.PHNXUSD : 0
1027 }
1028 } else {
1029 return {
1030 BTC: this.state.ETHBTC ? this.state.ETHBTC : 0,
1031 USD: this.state.ETHUSD ? this.state.ETHUSD : 0
1032 }
1033 }
1034 }
1035 /**
1036 * Set graph data
1037 */
1038 setGraphData = (graphData) => {
1039 // var graphData = [];
1040 var fullGraphData = [];
1041
1042 if (graphData.length > 0) {
1043 /**
1044 * New algo here
1045 */
1046 graphData = _.orderBy(graphData, ['timestamp'], ['desc']);
1047
1048 graphData.map((thread) => {
1049
1050 fullGraphData.push({
1051 label: thread.timestamp,
1052 displayValue: thread.coin_price_btc ? `${parseFloat(thread.coin_price_btc).toFixed(6)} BTC` : '0 BTC',
1053 value: thread.coin_price_usd ? parseFloat(thread.coin_price_usd).toFixed(2) : 0.00
1054 });
1055 return thread
1056 })
1057 }
1058
1059 this.setGraphDataWithCustomLable(fullGraphData)
1060
1061 }
1062
1063 getMonthAndDate(month) {
1064 return moment().subtract(Math.abs(month), 'months').toISOString()
1065 }
1066
1067 setGraphDataWithCustomLable = async (fullGraphData) => {
1068 const { graphHistoryFlag } = this.state;
1069 /**
1070 * data array here
1071 */
1072 var graphDataArray = [];
1073 if (graphHistoryFlag === 'week') {
1074 graphDataArray = [
1075 {
1076 label: moment(moment().subtract(6, 'days').utc()).format('MMM D'),
1077 displayValue: '0 BTC',
1078 value: 0,
1079 amountBTC: 0
1080 },
1081 {
1082 label: moment(moment().subtract(5, 'days').utc()).format('MMM D'),
1083 displayValue: '0 BTC',
1084 value: 0,
1085 amountBTC: 0
1086 },
1087 {
1088 label: moment(moment().subtract(4, 'days').utc()).format('MMM D'),
1089 displayValue: '0 BTC',
1090 value: 0,
1091 amountBTC: 0
1092 },
1093 {
1094 label: moment(moment().subtract(3, 'days').utc()).format('MMM D'),
1095 displayValue: '0 BTC',
1096 value: 0,
1097 amountBTC: 0
1098 },
1099 {
1100 label: moment(moment().subtract(2, 'days').utc()).format('MMM D'),
1101 displayValue: '0 BTC',
1102 value: 0,
1103 amountBTC: 0
1104 },
1105 {
1106 label: moment(moment().subtract(1, 'days').utc()).format('MMM D'),
1107 displayValue: '0 BTC',
1108 value: 0,
1109 amountBTC: 0
1110 },
1111 {
1112 label: moment(moment().subtract(0, 'days').utc()).format('MMM D'),
1113 displayValue: '0 BTC',
1114 value: 0,
1115 amountBTC: 0
1116 }
1117 ]
1118
1119 fullGraphData = [
1120 fullGraphData[6] ? fullGraphData[6] : {
1121 label: moment(moment().subtract(6, 'days').utc()).format('MMM D'),
1122 displayValue: '0 BTC',
1123 value: 0,
1124 amountBTC: 0
1125 },
1126 fullGraphData[5] ? fullGraphData[5] : {
1127 label: moment(moment().subtract(5, 'days').utc()).format('MMM D'),
1128 displayValue: '0 BTC',
1129 value: 0,
1130 amountBTC: 0
1131 },
1132 fullGraphData[4] ? fullGraphData[4] : {
1133 label: moment(moment().subtract(4, 'days').utc()).format('MMM D'),
1134 displayValue: '0 BTC',
1135 value: 0,
1136 amountBTC: 0
1137 },
1138 fullGraphData[3] ? fullGraphData[3] : {
1139 label: moment(moment().subtract(3, 'days').utc()).format('MMM D'),
1140 displayValue: '0 BTC',
1141 value: 0,
1142 amountBTC: 0
1143 },
1144 fullGraphData[2] ? fullGraphData[2] : {
1145 label: moment(moment().subtract(2, 'days').utc()).format('MMM D'),
1146 displayValue: '0 BTC',
1147 value: 0,
1148 amountBTC: 0
1149 },
1150 fullGraphData[1] ? fullGraphData[1] : {
1151 label: moment(moment().subtract(1, 'days').utc()).format('MMM D'),
1152 displayValue: '0 BTC',
1153 value: 0,
1154 amountBTC: 0
1155 },
1156 fullGraphData[0] ? fullGraphData[0] : {
1157 label: moment(moment().subtract(0, 'days').utc()).format('MMM D'),
1158 displayValue: '0 BTC',
1159 value: 0,
1160 amountBTC: 0
1161 }
1162 ]
1163 } else if (graphHistoryFlag === 'year') {
1164 graphDataArray = []
1165 graphDataArray = [
1166 {
1167 label: moment(moment().subtract(Math.abs(11), 'months').utc()).format('MMM YYYY'),
1168 displayValue: '01 BTC',
1169 value: 0,
1170 amountBTC: 0
1171 },
1172 {
1173 label: moment(moment().subtract(Math.abs(10), 'months').utc()).format('MMM YYYY'),
1174 displayValue: '0 BTC',
1175 value: 0,
1176 amountBTC: 0
1177 },
1178 {
1179 label: moment(moment().subtract(Math.abs(9), 'months').utc()).format('MMM YYYY'),
1180 displayValue: '0 BTC',
1181 value: 0,
1182 amountBTC: 0
1183 },
1184 {
1185 label: moment(moment().subtract(Math.abs(8), 'months').utc()).format('MMM YYYY'),
1186 displayValue: '0 BTC',
1187 value: 0,
1188 amountBTC: 0
1189 },
1190 {
1191 label: moment(moment().subtract(Math.abs(7), 'months').utc()).format('MMM YYYY'),
1192 displayValue: '0 BTC',
1193 value: 0,
1194 amountBTC: 0
1195 },
1196 {
1197 label: moment(moment().subtract(Math.abs(6), 'months').utc()).format('MMM YYYY'),
1198 displayValue: '0 BTC',
1199 value: 0,
1200 amountBTC: 0
1201 },
1202 {
1203 label: moment(moment().subtract(Math.abs(5), 'months').utc()).format('MMM YYYY'),
1204 displayValue: '0 BTC',
1205 value: 0,
1206 amountBTC: 0
1207 },
1208 {
1209 label: moment(moment().subtract(Math.abs(4), 'months').utc()).format('MMM YYYY'),
1210 displayValue: '0 BTC',
1211 value: 0,
1212 amountBTC: 0
1213 },
1214 {
1215 label: moment(moment().subtract(Math.abs(3), 'months').utc()).format('MMM YYYY'),
1216 displayValue: '0 BTC',
1217 value: 0,
1218 amountBTC: 0
1219 },
1220 {
1221 label: moment(moment().subtract(Math.abs(2), 'months').utc()).format('MMM YYYY'),
1222 displayValue: '0 BTC',
1223 value: 0,
1224 amountBTC: 0
1225 },
1226 {
1227 label: moment(moment().subtract(Math.abs(1), 'months').utc()).format('MMM YYYY'),
1228 displayValue: '0 BTC',
1229 value: 0,
1230 amountBTC: 0
1231 },
1232 {
1233 label: moment(moment().subtract(Math.abs(0), 'months').utc()).format('MMM YYYY'),
1234 displayValue: '0 BTC',
1235 value: 0,
1236 amountBTC: 0
1237 }
1238 ]
1239
1240 fullGraphData = [
1241 fullGraphData[330] ? fullGraphData[330] : {
1242 label: moment(moment().subtract(Math.abs(11), 'months').utc()).format('MMM YYYY'),
1243 displayValue: '01 BTC',
1244 value: 0,
1245 amountBTC: 0
1246 },
1247 fullGraphData[300] ? fullGraphData[300] : {
1248 label: moment(moment().subtract(Math.abs(10), 'months').utc()).format('MMM YYYY'),
1249 displayValue: '0 BTC',
1250 value: 0,
1251 amountBTC: 0
1252 },
1253 fullGraphData[270] ? fullGraphData[270] : {
1254 label: moment(moment().subtract(Math.abs(9), 'months').utc()).format('MMM YYYY'),
1255 displayValue: '0 BTC',
1256 value: 0,
1257 amountBTC: 0
1258 },
1259 fullGraphData[240] ? fullGraphData[240] : {
1260 label: moment(moment().subtract(Math.abs(8), 'months').utc()).format('MMM YYYY'),
1261 displayValue: '0 BTC',
1262 value: 0,
1263 amountBTC: 0
1264 },
1265 fullGraphData[210] ? fullGraphData[210] : {
1266 label: moment(moment().subtract(Math.abs(7), 'months').utc()).format('MMM YYYY'),
1267 displayValue: '0 BTC',
1268 value: 0,
1269 amountBTC: 0
1270 },
1271 fullGraphData[180] ? fullGraphData[180] : {
1272 label: moment(moment().subtract(Math.abs(6), 'months').utc()).format('MMM YYYY'),
1273 displayValue: '0 BTC',
1274 value: 0,
1275 amountBTC: 0
1276 },
1277 fullGraphData[150] ? fullGraphData[150] : {
1278 label: moment(moment().subtract(Math.abs(5), 'months').utc()).format('MMM YYYY'),
1279 displayValue: '0 BTC',
1280 value: 0,
1281 amountBTC: 0
1282 },
1283 fullGraphData[120] ? fullGraphData[120] : {
1284 label: moment(moment().subtract(Math.abs(4), 'months').utc()).format('MMM YYYY'),
1285 displayValue: '0 BTC',
1286 value: 0,
1287 amountBTC: 0
1288 },
1289 fullGraphData[90] ? fullGraphData[90] : {
1290 label: moment(moment().subtract(Math.abs(3), 'months').utc()).format('MMM YYYY'),
1291 displayValue: '0 BTC',
1292 value: 0,
1293 amountBTC: 0
1294 },
1295 fullGraphData[60] ? fullGraphData[60] : {
1296 label: moment(moment().subtract(Math.abs(2), 'months').utc()).format('MMM YYYY'),
1297 displayValue: '0 BTC',
1298 value: 0,
1299 amountBTC: 0
1300 },
1301 fullGraphData[30] ? fullGraphData[30] : {
1302 label: moment(moment().subtract(Math.abs(1), 'months').utc()).format('MMM YYYY'),
1303 displayValue: '0 BTC',
1304 value: 0,
1305 amountBTC: 0
1306 },
1307 fullGraphData[0] ? fullGraphData[0] : {
1308 label: moment(moment().subtract(Math.abs(0), 'months').utc()).format('MMM YYYY'),
1309 displayValue: '0 BTC',
1310 value: 0,
1311 amountBTC: 0
1312 }
1313 ]
1314 } else if (graphHistoryFlag === 'm_1') {
1315 graphDataArray = []
1316 graphDataArray = [
1317 {
1318 label: moment(moment().subtract(30, 'days').utc()).format('MMM D'),
1319 displayValue: '0 BTC',
1320 value: 0,
1321 amountBTC: 0
1322 },
1323 {
1324 label: moment(moment().subtract(25, 'days').utc()).format('MMM D'),
1325 displayValue: '0 BTC',
1326 value: 0,
1327 amountBTC: 0
1328 },
1329 {
1330 label: moment(moment().subtract(20, 'days').utc()).format('MMM D'),
1331 displayValue: '0 BTC',
1332 value: 0,
1333 amountBTC: 0
1334 },
1335 {
1336 label: moment(moment().subtract(15, 'days').utc()).format('MMM D'),
1337 displayValue: '0 BTC',
1338 value: 0,
1339 amountBTC: 0
1340 },
1341 {
1342 label: moment(moment().subtract(10, 'days').utc()).format('MMM D'),
1343 displayValue: '0 BTC',
1344 value: 0,
1345 amountBTC: 0
1346 },
1347 {
1348 label: moment(moment().subtract(5, 'days').utc()).format('MMM D'),
1349 displayValue: '0 BTC',
1350 value: 0,
1351 amountBTC: 0
1352 },
1353 {
1354 label: moment(moment().subtract(0, 'days').utc()).format('MMM D'),
1355 displayValue: '0 BTC',
1356 value: 0,
1357 amountBTC: 0
1358 },
1359 ]
1360
1361 fullGraphData = [
1362 fullGraphData[30] ? fullGraphData[30] : {
1363 label: moment(moment().subtract(30, 'days').utc()).format('MMM D'),
1364 displayValue: '0 BTC',
1365 value: 0,
1366 amountBTC: 0
1367 },
1368 fullGraphData[25] ? fullGraphData[25] : {
1369 label: moment(moment().subtract(25, 'days').utc()).format('MMM D'),
1370 displayValue: '0 BTC',
1371 value: 0,
1372 amountBTC: 0
1373 },
1374 fullGraphData[20] ? fullGraphData[20] : {
1375 label: moment(moment().subtract(20, 'days').utc()).format('MMM D'),
1376 displayValue: '0 BTC',
1377 value: 0,
1378 amountBTC: 0
1379 },
1380 fullGraphData[15] ? fullGraphData[15] : {
1381 label: moment(moment().subtract(15, 'days').utc()).format('MMM D'),
1382 displayValue: '0 BTC',
1383 value: 0,
1384 amountBTC: 0
1385 },
1386 fullGraphData[10] ? fullGraphData[10] : {
1387 label: moment(moment().subtract(10, 'days').utc()).format('MMM D'),
1388 displayValue: '0 BTC',
1389 value: 0,
1390 amountBTC: 0
1391 },
1392 fullGraphData[5] ? fullGraphData[5] : {
1393 label: moment(moment().subtract(5, 'days').utc()).format('MMM D'),
1394 displayValue: '0 BTC',
1395 value: 0,
1396 amountBTC: 0
1397 },
1398 fullGraphData[0] ? fullGraphData[0] : {
1399 label: moment(moment().subtract(0, 'days').utc()).format('MMM D'),
1400 displayValue: '0 BTC',
1401 value: 0,
1402 amountBTC: 0
1403 },
1404 ]
1405 }
1406
1407 if (fullGraphData && fullGraphData.length > 0) {
1408 graphDataArray = graphDataArray.map((thread, index) => {
1409 if (fullGraphData[index]) {
1410 return thread = {
1411 label: thread.label,
1412 displayValue: fullGraphData[index].displayValue,
1413 value: fullGraphData[index].value
1414 }
1415 } else {
1416 return thread
1417 }
1418 })
1419 }
1420
1421 this.setState({
1422 graphDataWithLabels: graphDataArray
1423 })
1424
1425 }
1426
1427 /**
1428 * Update allTransactionHistory
1429 */
1430 updateTransactionHistory = (transactionHistoryFlag, transactions) => {
1431 let { allTempTransactions } = this.state;
1432 if (transactions && (transactionHistoryFlag === 'all')) {
1433 let allTransactions = [];
1434 if (transactions.deposits.length > 0) {
1435 transactions.deposits.map((deposit) => {
1436 allTransactions.push(deposit)
1437 return deposit
1438 });
1439 }
1440
1441 if (transactions.withdrawals.length > 0) {
1442 transactions.withdrawals.map((withdrawal) => {
1443 allTransactions.push(withdrawal)
1444 return withdrawal
1445 });
1446 }
1447
1448 allTransactions = _.orderBy(allTransactions, ['timestamp'], ['desc']);
1449 /**
1450 * remove txns from temp arrya if it's available in live
1451 */
1452 allTempTransactions = allTempTransactions.filter((thread) => {
1453 const checkTxn = _.some(allTransactions, { 'amount': thread.amount, 'from': thread.from, 'to': thread.to, 'token': thread.token });
1454 if (!checkTxn) {
1455 return thread
1456 }
1457 })
1458 this.setState({
1459 allTransactionHistory: allTransactions,
1460 filterTransactionHistory: allTransactions,
1461 allTempTransactions: allTempTransactions
1462 });
1463 }
1464 }
1465
1466 getAllTokens = () => {
1467 this.setState({
1468 isLoadingCryptoAsset: true
1469 })
1470 const header = this.props.client_manager.auth.getHeader();
1471 this.props.client_manager.service.getTokenList(header,
1472 (data) => {
1473 if (data.data.tokens.length > 0) {
1474 let tokens = data.data.tokens.map((token) => {
1475 return {
1476 ...token,
1477 label: token.name,
1478 value: token.symbol
1479 }
1480 })
1481 this.setState({
1482 tokensList: tokens
1483 })
1484 if (tokens.length < 1) {
1485 this.getAllTokens()
1486 } else {
1487 this.setState({
1488 isLoadingCryptoAsset: false
1489 })
1490 }
1491 }
1492
1493 },
1494 (error) => {
1495 this.setState({
1496 isLoadingCryptoAsset: false
1497 })
1498 })
1499
1500 }
1501
1502 handleCryptoAssetChange = cryptoAsset => {
1503 this.setState(
1504 {
1505 cryptoAsset: cryptoAsset,
1506 cryptoAssetError: false
1507 }
1508 );
1509 };
1510
1511 handleTokenAssetChange = cryptoAsset => {
1512 this.setState(
1513 {
1514 tokenAsset: cryptoAsset,
1515 tokenAssetError: false
1516 }
1517 );
1518 };
1519
1520 handleOnChangeSlider = sharedVaultData_maxSigner => {
1521 if ((parseInt(sharedVaultData_maxSigner, 10) >= 2) && (parseInt(sharedVaultData_maxSigner, 10) < 6)) {
1522 this.setState(
1523 { sharedVaultData_maxSigner }
1524 );
1525 }
1526 };
1527
1528 /**
1529 * Get Shared Vault balance
1530 */
1531 getSharedVaultsBalance = (isLoading, vaultData) => {
1532 this.setState({
1533 isLoadingBalance: isLoading
1534 })
1535
1536 const header = this.props.client_manager.auth.getHeader();
1537 const userDeatils = this.props.client_manager.auth.getUserDetails();
1538 if (this.props.vaultData || vaultData) {
1539 const vaultID = vaultData ? vaultData._id : this.props.vaultData._id;
1540 const currency = vaultData ? vaultData.currency : this.props.vaultData.currency;
1541
1542 this.props.client_manager.service.getSharedSingleVaultBalance(
1543 header,
1544 vaultID,
1545 currency,
1546 (data) => {
1547 this.setState({
1548 isLoadingBalance: false,
1549 totalBalance: data.data.balance
1550 })
1551 const balanceData = [{
1552 balances: data.data.balance,
1553 currency: currency
1554 }]
1555 this.updateVaultBalance(balanceData)
1556 },
1557 (error) => {
1558 const balanceData = [{
1559 balances: 0,
1560 currency: currency
1561 }]
1562 this.updateVaultBalance(balanceData)
1563 this.setState({
1564 isLoadingBalance: false,
1565 totalBalance: 0
1566 })
1567 });
1568 } else if (userDeatils.user_vault_id) {
1569 const vaultID = userDeatils.user_vault_id;
1570 const currency = userDeatils.user_vault_currency;
1571
1572 this.props.client_manager.service.getSharedSingleVaultBalance(
1573 header,
1574 vaultID,
1575 currency,
1576 (data) => {
1577 this.setState({
1578 isLoadingBalance: false,
1579 totalBalance: data.data.balance
1580 })
1581 const balanceData = [{
1582 balances: data.data.balance,
1583 currency: currency
1584 }]
1585 this.updateVaultBalance(balanceData)
1586 },
1587 (error) => {
1588 this.setState({
1589 isLoadingBalance: false
1590 })
1591 });
1592 } else {
1593 this.props.client_manager.service.getSharedAllVaultBalance(
1594 header,
1595 (data) => {
1596 this.setState({
1597 isLoadingBalance: false
1598 })
1599 this.updateVaultBalance(data.data.vaults)
1600 },
1601 (error) => {
1602 if (error && error.response && error.response.status && error.response.status === 401) {
1603 this.props.history.push('/login')
1604 }
1605 this.setState({
1606 isLoadingBalance: false
1607 })
1608 });
1609 }
1610 }
1611 /**
1612 * Get Transaction history on dashboard
1613 */
1614 getVaultsBalance = (isLoading, vaultData) => {
1615 this.setState({
1616 isLoadingBalance: isLoading
1617 })
1618
1619 const header = this.props.client_manager.auth.getHeader();
1620 const userDeatils = this.props.client_manager.auth.getUserDetails();
1621
1622 if (this.props.vaultData || vaultData) {
1623 var vaultID = vaultData ? vaultData._id : this.props.vaultData._id;
1624
1625 this.props.client_manager.service.getSingleVaultBalance(
1626 header,
1627 vaultID,
1628 (data) => {
1629 this.setState({
1630 isLoadingBalance: false,
1631 })
1632
1633 if(data && data.data && data.data.results && data.data.results.length > 0) {
1634 const updatedBalance = data.data.results.map((thread) => {
1635 return {
1636 ...thread,
1637 currency: thread.token,
1638 balances: thread.balance
1639 }
1640 })
1641 this.updateVaultBalance(updatedBalance)
1642 this.getTotalBalance(vaultID, 'single')
1643 }
1644 },
1645 (error) => {
1646 this.setState({
1647 isLoadingBalance: false
1648 })
1649 });
1650 } else if (userDeatils.user_vault_id) {
1651 const vaultID = userDeatils.user_vault_id;
1652 const currency = userDeatils.user_vault_currency;
1653 this.getTotalBalance(vaultID, 'single')
1654 this.props.client_manager.service.getSingleVaultBalance(
1655 header,
1656 vaultID,
1657 (data) => {
1658 this.setState({
1659 isLoadingBalance: false
1660 })
1661
1662 if(data && data.data && data.data.results && data.data.results.length > 0) {
1663 const updatedBalance = data.data.results.map((thread) => {
1664 return {
1665 ...thread,
1666 currency: thread.token,
1667 balances: thread.balance
1668 }
1669 })
1670 this.updateVaultBalance(updatedBalance)
1671 }
1672
1673 },
1674 (error) => {
1675 this.setState({
1676 isLoadingBalance: false
1677 })
1678 });
1679 } else {
1680 this.props.client_manager.service.getBalanceAllVaults(
1681 header,
1682 (data) => {
1683 this.setState({
1684 isLoadingBalance: false
1685 })
1686 this.updateVaultBalance(data.data.vaults)
1687 },
1688 (error) => {
1689 this.setState({
1690 isLoadingBalance: false
1691 })
1692 });
1693 }
1694 }
1695
1696 onCloseAction = (e) => {
1697 this.props.history.push('/dashboard')
1698 }
1699
1700 onCloseWithdrawAction = (e) => {
1701 this.setState({
1702 authfade: false,
1703 authmodal: false
1704 })
1705 }
1706
1707 handleToken = (e) => {
1708 const key = e.target.id;
1709 this.setState({
1710 [key]: e.target.value
1711 }, () => {
1712 if (this.state.token && this.state.token.length === 6) {
1713 this.onSubmitGoogleAuthTokenForAddNewVault(e, true)
1714 }
1715 })
1716 }
1717 /**
1718 * Get Shared Vault List
1719 */
1720 getSharedVaultList = (data, isLoading) => {
1721 const header = this.props.client_manager.auth.getHeader();
1722 this.props.client_manager.service.getSharedAllVaultBalance(
1723 header,
1724 (response) => {
1725 this.setState({
1726 isLoadingBalance: false
1727 })
1728 var filterdVaults = response.data.vaults.length > 0 ? response.data.vaults.filter((row) => row.allAccepted === true) : []
1729
1730 const newVaults = [...data.data.vaults, ...response.data.vaults];
1731 filterdVaults = [...data.data.vaults, ...filterdVaults];
1732
1733 let vaults = newVaults.map((vault) => {
1734
1735 return {
1736 ...vault,
1737 type: vault.type === 'single' ? 'single' : 'shared',
1738 label: vault.name,
1739 value: vault.address
1740 }
1741 })
1742
1743 filterdVaults = filterdVaults.map((vault) => {
1744
1745 return {
1746 ...vault,
1747 type: vault.type === 'single' ? 'single' : 'shared',
1748 label: vault.name,
1749 value: vault.address
1750 }
1751 })
1752 let optionVaults = [];
1753 if (filterdVaults.length > 0) {
1754 optionVaults = [{
1755 label: 'ALL VAULTS',
1756 value: 'ALL VAULTS'
1757 }, ...filterdVaults]
1758 }
1759
1760 this.setState({
1761 vaults: filterdVaults,
1762 allVaults: vaults,
1763 optionVaults: optionVaults,
1764 filterAllVaults: filterdVaults
1765 })
1766 this.props.client_manager.auth.saveUserPreVault(vaults[0]);
1767
1768 },
1769 (error) => {
1770 if (error && error.response && error.response.status && error.response.status === 401) {
1771 this.props.history.push('/login')
1772 }
1773 this.setState({
1774 isLoadingBalance: false
1775 })
1776 });
1777 }
1778 /**
1779 * Update All vaults data
1780 */
1781 updateVaultList = (isLoading) => {
1782
1783 const header = this.props.client_manager.auth.getHeader();
1784
1785 this.props.client_manager.service.getBalanceAllVaults(
1786 header,
1787 (data) => {
1788 /**
1789 * Get Shared Vault list also
1790 */
1791 this.getSharedVaultList(data, isLoading)
1792 },
1793 (error) => {
1794 this.setState({
1795 isLoadingBalance: false
1796 })
1797 });
1798 }
1799
1800 onChangeVaultType = (e) => {
1801 const key = e.target.name;
1802 if (e.target.value === 'shared') {
1803 this.props.history.push('/sharedVault')
1804 }
1805 this.setState({
1806 [key]: e.target.value
1807 })
1808 }
1809
1810 updateVaultBalance = (vaults) => {
1811
1812 this.setState({
1813 vaultsBalance: vaults
1814 })
1815 }
1816 /**
1817 * Get Logged in user info
1818 */
1819 getUserInfo = () => {
1820 const header = this.props.client_manager.auth.getHeader();
1821 this.props.client_manager.service.getUserInfo(
1822 header,
1823 (data) => {
1824 this.setUserProfileInfo(data.data.profile);
1825 },
1826 (error) => {
1827 });
1828 }
1829 /**
1830 * onFilterTransactions
1831 */
1832 onFilterTransactions = (e, transactionType) => {
1833 e.preventDefault();
1834 let { allTransactionHistory, filterTransactionHistory, allTempTransactions } = this.state;
1835
1836 this.setState(({
1837 transactionHistoryFlag: transactionType
1838 }))
1839
1840 if (transactionType === 'receive') {
1841 filterTransactionHistory = allTransactionHistory.filter((transaction, idx) => {
1842 return transaction.transaction_type === 'deposit'
1843 });
1844 filterTransactionHistory = _.orderBy(filterTransactionHistory, ['timestamp'], ['desc']);
1845 /**
1846 * remove txns from temp arrya if it's available in live
1847 */
1848 allTempTransactions = allTempTransactions.filter((thread) => {
1849 const checkTxn = _.some(filterTransactionHistory, { 'amount': thread.amount, 'from': thread.from, 'to': thread.to, 'token': thread.token });
1850 if (!checkTxn) {
1851 return thread
1852 }
1853 })
1854 this.setState({
1855 filterTransactionHistory,
1856 allTempTransactions
1857 })
1858 }
1859 if (transactionType === 'sent') {
1860 filterTransactionHistory = allTransactionHistory.filter((transaction, idx) => {
1861 return transaction.transaction_type === 'withdraw'
1862 });
1863 filterTransactionHistory = _.orderBy(filterTransactionHistory, ['timestamp'], ['desc']);
1864
1865 allTempTransactions = allTempTransactions.filter((thread) => {
1866 const checkTxn = _.some(filterTransactionHistory, { 'amount': thread.amount, 'from': thread.from, 'to': thread.to, 'token': thread.token });
1867 if (!checkTxn) {
1868 return thread
1869 }
1870 })
1871
1872 this.setState({
1873 filterTransactionHistory,
1874 allTempTransactions
1875 })
1876 }
1877
1878 if (transactionType === 'all') {
1879 filterTransactionHistory = allTransactionHistory.filter((transaction, idx) => {
1880 return transaction.transaction_type === 'withdraw' || transaction.transaction_type === 'deposit'
1881 });
1882 filterTransactionHistory = _.orderBy(filterTransactionHistory, ['timestamp'], ['desc']);
1883
1884 allTempTransactions = allTempTransactions.filter((thread) => {
1885 const checkTxn = _.some(filterTransactionHistory, { 'amount': thread.amount, 'from': thread.from, 'to': thread.to, 'token': thread.token });
1886 if (!checkTxn) {
1887 return thread
1888 }
1889 })
1890
1891 this.setState({
1892 filterTransactionHistory,
1893 allTempTransactions
1894 })
1895 }
1896 }
1897
1898 /**
1899 * onFilterTransactions
1900 */
1901 onFilterTransactionsByVault = (e, vaultType) => {
1902 e.preventDefault();
1903
1904 let { allTransactionHistory, filterTransactionHistory, allTempTransactions } = this.state;
1905
1906 if (vaultType === 'single') {
1907 filterTransactionHistory = allTransactionHistory.filter((transaction, idx) => {
1908 const txnVaultType = transaction.sharedVault ? transaction.sharedVault.type : transaction.vault.type;
1909 return txnVaultType === 'single'
1910 });
1911 filterTransactionHistory = _.orderBy(filterTransactionHistory, ['timestamp'], ['desc']);
1912
1913 allTempTransactions = allTempTransactions.filter((thread) => {
1914 const checkTxn = _.some(filterTransactionHistory, { 'amount': thread.amount, 'from': thread.from, 'to': thread.to, 'token': thread.token });
1915 if (!checkTxn) {
1916 return thread
1917 }
1918 })
1919
1920 this.setState({
1921 filterTransactionHistory,
1922 allTempTransactions
1923 })
1924 }
1925 if (vaultType === 'shared') {
1926 filterTransactionHistory = allTransactionHistory.filter((transaction, idx) => {
1927 const txnVaultType = transaction.sharedVault ? transaction.sharedVault.type : transaction.vault.type;
1928 return txnVaultType === 'shared'
1929 });
1930 filterTransactionHistory = _.orderBy(filterTransactionHistory, ['timestamp'], ['desc']);
1931
1932 allTempTransactions = allTempTransactions.filter((thread) => {
1933 const checkTxn = _.some(filterTransactionHistory, { 'amount': thread.amount, 'from': thread.from, 'to': thread.to, 'token': thread.token });
1934 if (!checkTxn) {
1935 return thread
1936 }
1937 })
1938
1939 this.setState({
1940 filterTransactionHistory,
1941 allTempTransactions
1942 })
1943 }
1944 if (vaultType === 'all') {
1945 filterTransactionHistory = _.orderBy(allTransactionHistory, ['timestamp'], ['desc']);
1946
1947 allTempTransactions = allTempTransactions.filter((thread) => {
1948 const checkTxn = _.some(filterTransactionHistory, { 'amount': thread.amount, 'from': thread.from, 'to': thread.to, 'token': thread.token });
1949 if (!checkTxn) {
1950 return thread
1951 }
1952 })
1953
1954 this.setState({
1955 filterTransactionHistory,
1956 allTempTransactions
1957 })
1958 }
1959 }
1960
1961 onCloseActionAddVault2FA = () => {
1962 this.setState({
1963 modal: false,
1964 fade: false
1965 })
1966 };
1967
1968 onSubmitAddVault = (e, vaultInfo) => {
1969 e.preventDefault()
1970 const { vaultName, cryptoAsset } = this.state;
1971
1972 if ((vaultName && cryptoAsset && vaultInfo.cosignerArray.length > 0) && (vaultInfo && (vaultInfo.vaultType === 'shared'))) {
1973 this.setState({
1974 modal: true,
1975 fade: true,
1976 isAddNewVault: true,
1977 vaultType: vaultInfo && vaultInfo.vaultType,
1978 sharedVaultData_vaultName: vaultName,
1979 sharedVaultData_cryptoAsset: cryptoAsset,
1980 sharedVaultData_coSignerData: vaultInfo && vaultInfo.cosignerArray,
1981 sharedVaultData_maxSigner: vaultInfo && vaultInfo.cosignerArray.length
1982 });
1983 /**
1984 * Need to call here create share vault function
1985 */
1986 this.createNewVaultWithoutAuth()
1987 } else if (vaultName && cryptoAsset && (vaultInfo && (vaultInfo.vaultType === 'single'))) {
1988 this.setState({
1989 modal: true,
1990 fade: true,
1991 isAddNewVault: true,
1992 vaultType: vaultInfo && vaultInfo.vaultType,
1993 });
1994 /**
1995 * Need to call here create single vault function
1996 */
1997 this.createNewVaultWithoutAuth()
1998 } else {
1999 this.setState({
2000 vaultNameError: !vaultName && true,
2001 vaultNameError_text: 'Please enter a Vault name.',
2002 cryptoAssetError: !cryptoAsset && true,
2003 cryptoAssetError_text: 'Please select an asset.'
2004 })
2005 }
2006 }
2007
2008 onSubmitAddToken = (e, vaultInfo) => {
2009 e.preventDefault()
2010 const { tokenAsset,configVaultSelect } = this.state;
2011
2012 if (tokenAsset) {
2013 this.setState({
2014 modal: true,
2015 fade: true,
2016 isAddNewToken: true
2017 });
2018
2019 this.addNewtoken();
2020
2021 } else {
2022 this.setState({
2023 tokenAssetError: !tokenAsset && true,
2024 tokenAssetError_text: 'Please select an asset.'
2025 })
2026 }
2027 }
2028
2029 setUserProfileInfo = (userInfo) => {
2030
2031 if (userInfo) {
2032 this.setState({
2033 email: userInfo.email,
2034 first_name: userInfo.first_name,
2035 last_name: userInfo.last_name,
2036 userImageData: userInfo.photo,
2037 secondary_email: userInfo.secondary_email,
2038 tfa_type: userInfo.tfa_type,
2039 userID: userInfo._id,
2040 selectedVault: this.props.vaultData,
2041 userPhoto: `https://numiovault.s3.us-east-2.amazonaws.com/${userInfo.photo}`
2042 });
2043 /**
2044 * Store userInfo in localstoreg
2045 */
2046 this.props.client_manager.auth.saveUserProfile(userInfo);
2047 }
2048 }
2049
2050 /**
2051 * Shared Vault functions
2052 */
2053 handleSharedVaultName = (e) => {
2054 const key = e.target.id
2055 this.setState({
2056 [key]: e.target.value
2057 })
2058 }
2059
2060 handleCryptoSelectForSharedVault = (crypto) => {
2061 this.setState({
2062 sharedVaultData_cryptoAsset: crypto
2063 })
2064 }
2065
2066 handleSharedVaultEmailCurrentCoSigner = (e) => {
2067 const key = e.target.id
2068 this.setState({
2069 [key]: e.target.value
2070 })
2071 }
2072
2073 handleAddCoSignerCountAndData = (e) => {
2074 const { sharedVaultData_currentSignerCount, sharedVaultData_coSignerData, sharedVaultData_currentCoSignerEmail } = this.state;
2075 /**
2076 * User can add as many coSigner want
2077 */
2078 if (sharedVaultData_coSignerData.length < 5 && sharedVaultData_currentCoSignerEmail) {
2079 sharedVaultData_coSignerData.push(sharedVaultData_currentCoSignerEmail)
2080 this.setState({
2081 sharedVaultData_currentSignerCount: sharedVaultData_currentSignerCount + 1,
2082 sharedVaultData_coSignerData: sharedVaultData_coSignerData,
2083 })
2084 }
2085 };
2086
2087 handleNextAllowedWhitelistUserAdd = (e) => {
2088 this.setState({
2089 whitelistUserName: undefined,
2090 whitelistUserEmail: undefined,
2091 whitelistUserAddress: undefined,
2092 isNextWhitelistUserAllowed: true
2093 })
2094 }
2095
2096 isValidEmailOrNot = (email) => {
2097 if (email) {
2098 if (isEmail(email)) {
2099 return undefined
2100 } else {
2101 return 'Please enter valid email address'
2102 }
2103 } else {
2104 return undefined
2105 }
2106 }
2107 handleUpdateWhitelistUserInput = (e, filedType, data, errorType, touchedValue) => {
2108 e.preventDefault();
2109 if (filedType === 'updateWhitelistUserEmail') {
2110 const newUsersData = this.state.whiteListUsersData.map((user, idx) => {
2111 if (user.whitelistId === data.whitelistId) {
2112 return Object.assign({}, { ...user }, { [filedType]: e.target.value }, { [errorType]: e.target.value ? this.isValidEmailOrNot(e.target.value) : 'Please fill out the required fields' }, { [touchedValue]: true })
2113 } else {
2114 return user
2115 }
2116 });
2117 this.setState({
2118 whiteListUsersData: newUsersData
2119 })
2120 } else {
2121 const newUsersData = this.state.whiteListUsersData.map((user, idx) => {
2122 if (user.whitelistId === data.whitelistId) {
2123 return Object.assign({}, { ...user }, { [filedType]: e.target.value }, { [errorType]: e.target.value ? undefined : 'Please fill out the required fields' }, { [touchedValue]: true })
2124 } else {
2125 return user
2126 }
2127 });
2128 this.setState({
2129 whiteListUsersData: newUsersData
2130 })
2131 }
2132 }
2133
2134
2135 handleUpdateWhitelistUser = (e, data) => {
2136 e.preventDefault()
2137 var { whiteListUsersData, configVaultSelect } = this.state;
2138
2139 if (!configVaultSelect) {
2140 toast(<WhitelistSettingsErrorMessage />,
2141 {
2142 position: toast.POSITION.TOP_RIGHT,
2143 className: 'Toastify__toast--dark',
2144 progressClassName: 'Toastify__progress-bar--dark-error'
2145 }
2146 )
2147 } else {
2148 if (data && (data.updateWhitelistUserName || (!data.isNameTouched && data.whitelistUserName)) && (data.updateWhitelistUserEmail || (!data.isEmailTouched && data.whitelistUserEmail)) && (data.updateWhitelistUserAddress || (!data.isAddressTouched && data.whitelistUserAddress))) {
2149
2150 this.setState({
2151 isWhitelistUpdateLoading: true,
2152 })
2153 const whiteListUserData = {
2154 name: data.updateWhitelistUserName ? data.updateWhitelistUserName : data.whitelistUserName,
2155 email: data.updateWhitelistUserEmail ? data.updateWhitelistUserEmail : data.whitelistUserEmail,
2156 address: data.updateWhitelistUserAddress ? data.updateWhitelistUserAddress : data.whitelistUserAddress,
2157 whitelist_id: data.whitelistId
2158 };
2159 const header = this.props.client_manager.auth.getHeader();
2160
2161 if (configVaultSelect) {
2162
2163 if (configVaultSelect.type === 'single') {
2164
2165 this.props.client_manager.service.updateWhitelistSingleVault(header, configVaultSelect._id, whiteListUserData,
2166 (res) => {
2167 whiteListUsersData = whiteListUsersData.map((whiteListUser) => {
2168 if (whiteListUser.whitelistId === data.whitelistId) {
2169 return {
2170 whitelistUserName: whiteListUserData.name,
2171 whitelistUserEmail: whiteListUserData.email,
2172 whitelistUserAddress: whiteListUserData.address,
2173 whitelistId: whiteListUserData.whitelist_id
2174 }
2175 } else {
2176 return whiteListUser
2177 }
2178 })
2179
2180 this.setState({
2181 whiteListUsersData: whiteListUsersData,
2182 updateWhitelistUserName: undefined,
2183 updateWhitelistUserEmail: undefined,
2184 updateWhitelistUserAddress: undefined,
2185 isWhitelistUpdateLoading: false
2186 })
2187
2188 toast(<ConfigWhitelistSuccessMessage />,
2189 {
2190 position: toast.POSITION.TOP_RIGHT,
2191 className: 'Toastify__toast--dark',
2192 progressClassName: 'Toastify__progress-bar--dark'
2193 }
2194 )
2195
2196 },
2197 (error) => {
2198 if (error && error.response && error.response.status && error.response.status === 401) {
2199 this.props.history.push('/login')
2200 }
2201 this.setState({
2202 error: error.response.data.payload.message,
2203 isWhitelistUpdateLoading: false,
2204 })
2205
2206 toast(<WhitelistSettingsErrorMessage />,
2207 {
2208 position: toast.POSITION.TOP_RIGHT,
2209 className: 'Toastify__toast--dark',
2210 progressClassName: 'Toastify__progress-bar--dark-error'
2211 }
2212 )
2213 })
2214
2215 } else if (configVaultSelect.type === 'shared') {
2216
2217 this.props.client_manager.service.updateWhitelistSharedVault(header, configVaultSelect._id, whiteListUserData,
2218 (res) => {
2219
2220 whiteListUsersData = whiteListUsersData.map((whiteListUser) => {
2221 if (whiteListUser.whitelistId === data.whitelistId) {
2222 return {
2223 whitelistUserName: whiteListUserData.name,
2224 whitelistUserEmail: whiteListUserData.email,
2225 whitelistUserAddress: whiteListUserData.address,
2226 whitelistId: whiteListUserData.whitelist_id
2227 }
2228 } else {
2229 return whiteListUser
2230 }
2231 })
2232
2233 this.setState({
2234 whiteListUsersData: whiteListUsersData,
2235 updateWhitelistUserName: undefined,
2236 updateWhitelistUserEmail: undefined,
2237 updateWhitelistUserAddress: undefined,
2238 isWhitelistUpdateLoading: false
2239 })
2240 toast(<ConfigWhitelistSuccessMessage />,
2241 {
2242 position: toast.POSITION.TOP_RIGHT,
2243 className: 'Toastify__toast--dark',
2244 progressClassName: 'Toastify__progress-bar--dark'
2245 }
2246 )
2247 },
2248 (error) => {
2249 if (error && error.response && error.response.status && error.response.status === 401) {
2250 this.props.history.push('/login')
2251 }
2252 this.setState({
2253 error: error.response.data.payload.message,
2254 isWhitelistUpdateLoading: false,
2255 })
2256
2257 toast(<WhitelistSettingsErrorMessage />,
2258 {
2259 position: toast.POSITION.TOP_RIGHT,
2260 className: 'Toastify__toast--dark',
2261 progressClassName: 'Toastify__progress-bar--dark-error'
2262 }
2263 )
2264 })
2265 }
2266 }
2267 }
2268 }
2269 }
2270
2271 getFilteredVaults = (e) => {
2272 const { allVaults } = this.state;
2273 if (allVaults && allVaults.length > 0) {
2274 const filterAllVaults = allVaults.filter(item => (item.name.toLowerCase()).indexOf((e.target.value).toLowerCase()) !== -1);
2275 this.setState(
2276 { filterAllVaults }
2277 );
2278 }
2279 }
2280
2281 handleAddWhitelistUsers = (e) => {
2282 const { whiteListUsersCount, whiteListUsersData, whitelistUserName, whitelistUserEmail, whitelistUserAddress, configVaultSelect, isNotifyUser } = this.state;
2283 if (!configVaultSelect) {
2284
2285 toast(<WhitelistSettingsErrorMessage />,
2286 {
2287 position: toast.POSITION.TOP_RIGHT,
2288 className: 'Toastify__toast--dark',
2289 progressClassName: 'Toastify__progress-bar--dark-error'
2290 }
2291 )
2292 } else {
2293 /**
2294 * Add validation on all field must be filed not empty
2295 */
2296 if (whitelistUserName && whitelistUserEmail && whitelistUserAddress) {
2297
2298 this.setState({
2299 isWhitelistAddSaveLoading: true,
2300 whitelistUserAddress_error: undefined,
2301 whitelistUserEmail_error: undefined,
2302 whitelistUserName_error: undefined,
2303 isNotifyUser: false
2304 })
2305
2306 const whiteListUserData = {
2307 name: whitelistUserName,
2308 email: whitelistUserEmail,
2309 address: whitelistUserAddress
2310 };
2311 const header = this.props.client_manager.auth.getHeader();
2312
2313 if (configVaultSelect) {
2314
2315 if (configVaultSelect.type === 'single') {
2316
2317 this.props.client_manager.service.addWhitelistSingleVault(header, configVaultSelect._id, whiteListUserData,
2318 (res) => {
2319 whiteListUsersData.push({
2320 whitelistUserName: whitelistUserName,
2321 whitelistUserEmail: whitelistUserEmail,
2322 whitelistUserAddress: whitelistUserAddress,
2323 whitelistNotify: isNotifyUser
2324 });
2325
2326 this.setState({
2327 whiteListUsersCount: whiteListUsersCount + 1,
2328 whiteListUsersData: whiteListUsersData,
2329 whitelistUserName: undefined,
2330 whitelistUserEmail: undefined,
2331 whitelistUserAddress: undefined,
2332 isNextWhitelistUserAllowed: true,
2333 isWhitelistAddSaveLoading: false,
2334 whitelistUserAddress_error: undefined,
2335 whitelistUserEmail_error: undefined,
2336 whitelistUserName_error: undefined,
2337 isNotifyUser: false
2338 })
2339
2340 toast(<ConfigWhitelistSuccessMessage />,
2341 {
2342 position: toast.POSITION.TOP_RIGHT,
2343 className: 'Toastify__toast--dark',
2344 progressClassName: 'Toastify__progress-bar--dark'
2345 }
2346 )
2347 },
2348 (error) => {
2349 if (error && error.response && error.response.status && error.response.status === 401) {
2350 this.props.history.push('/login')
2351 }
2352 this.setState({
2353 error: error.response.data.payload.message,
2354 isWhitelistAddSaveLoading: false,
2355 whitelistUserAddress_error: undefined,
2356 whitelistUserEmail_error: undefined,
2357 whitelistUserName_error: undefined,
2358 isNotifyUser: false
2359 })
2360
2361 toast(<WhitelistSettingsErrorMessage />,
2362 {
2363 position: toast.POSITION.TOP_RIGHT,
2364 className: 'Toastify__toast--dark',
2365 progressClassName: 'Toastify__progress-bar--dark-error'
2366 }
2367 )
2368 })
2369
2370
2371 } else if (configVaultSelect.type === 'shared') {
2372
2373 this.props.client_manager.service.addWhitelistSharedVault(header, configVaultSelect._id, whiteListUserData,
2374 (res) => {
2375 whiteListUsersData.push({
2376 whitelistUserName: whitelistUserName,
2377 whitelistUserEmail: whitelistUserEmail,
2378 whitelistUserAddress: whitelistUserAddress,
2379 whitelistNotify: isNotifyUser
2380 });
2381
2382 this.setState({
2383 whiteListUsersCount: whiteListUsersCount + 1,
2384 whiteListUsersData: whiteListUsersData,
2385 whitelistUserName: undefined,
2386 whitelistUserEmail: undefined,
2387 whitelistUserAddress: undefined,
2388 isNextWhitelistUserAllowed: true,
2389 isWhitelistAddSaveLoading: false,
2390 whitelistUserAddress_error: undefined,
2391 whitelistUserEmail_error: undefined,
2392 whitelistUserName_error: undefined,
2393 isNotifyUser: false
2394 })
2395
2396 toast(<ConfigWhitelistSuccessMessage />,
2397 {
2398 position: toast.POSITION.TOP_RIGHT,
2399 className: 'Toastify__toast--dark',
2400 progressClassName: 'Toastify__progress-bar--dark'
2401 }
2402 )
2403 },
2404 (error) => {
2405 if (error && error.response && error.response.status && error.response.status === 401) {
2406 this.props.history.push('/login')
2407 }
2408 this.setState({
2409 error: error.response.data.payload.message,
2410 isWhitelistAddSaveLoading: false,
2411 whitelistUserAddress_error: undefined,
2412 whitelistUserEmail_error: undefined,
2413 whitelistUserName_error: undefined,
2414 isNotifyUser: false
2415 })
2416
2417 toast(<WhitelistSettingsErrorMessage />,
2418 {
2419 position: toast.POSITION.TOP_RIGHT,
2420 className: 'Toastify__toast--dark',
2421 progressClassName: 'Toastify__progress-bar--dark-error'
2422 }
2423 )
2424 })
2425 }
2426 }
2427 } else {
2428 if (!whitelistUserAddress) {
2429 this.setState({
2430 whitelistUserAddress_error: 'Please fill out the required fields'
2431 })
2432 }
2433 if (!whitelistUserEmail) {
2434 this.setState({
2435 whitelistUserEmail_error: 'Please fill out the required fields'
2436 })
2437 }
2438 if (!whitelistUserName) {
2439 this.setState({
2440 whitelistUserName_error: 'Please fill out the required fields'
2441 })
2442 }
2443 }
2444 }
2445 }
2446
2447
2448 onStepTwoSharedVault = () => {
2449 this.setState({
2450 isCoSignerModalOpen: false,
2451 isOpenAuthForCreateSharedVault: false,
2452 isCoSignerWarningPopupEnable: true,
2453 isCoSignerWarningPopupModal: true,
2454 isCoSignerWarningPopupFade: true,
2455 })
2456 }
2457
2458 onStepThreeSharedVault = async () => {
2459 /**
2460 * Need to Make the API call to create shared vault
2461 */
2462 await this.createSharedVault();
2463 }
2464
2465 createSharedVault = () => {
2466 this.setState({
2467 isCreatingSharedVault: true
2468 })
2469 let { sharedVaultData_vaultName, sharedVaultData_cryptoAsset, sharedVaultData_coSignerData, sharedVaultData_maxSigner } = this.state;
2470 let coSignerNamesArr = [];
2471 sharedVaultData_coSignerData.forEach((singer) => {
2472 coSignerNamesArr.push(singer.name)
2473 })
2474 const form = {
2475 name: sharedVaultData_vaultName,
2476 currency: sharedVaultData_cryptoAsset.symbol,
2477 signers: coSignerNamesArr,
2478 numberOfSignatures: sharedVaultData_maxSigner,
2479 numberOfSigners: sharedVaultData_coSignerData.length,
2480 }
2481 const header = this.props.client_manager.auth.getHeader();
2482 this.props.client_manager.service.createSharedVault(header, form,
2483 (res) => {
2484 this.setState({
2485 isCreatingSharedVault: false,
2486 isGAuthLoading: false,
2487 isSummaryPage: true,
2488 modal: false,
2489 fade: false
2490 })
2491
2492 toast.success('Shared Vault creation request has been sent to Co-Singers',
2493 {
2494 position: toast.POSITION.TOP_RIGHT
2495 });
2496 this.props.history.push('/dashboard')
2497
2498 },
2499 (error) => {
2500 this.setState({
2501 error: error.response.data.payload.message,
2502 isCreatingSharedVault: false,
2503 isGAuthLoading: false
2504 })
2505 })
2506 }
2507
2508 onSubmitGoogleAuthToken = (e, isAutoSubmit) => {
2509 if (!isAutoSubmit) {
2510 e.preventDefault()
2511 }
2512 if (!this.state.token) {
2513 this.setState({
2514 twoFA_error: 'Please enter the code from your 2FA application.',
2515 isGAuthLoading: false
2516 })
2517 return
2518 }
2519 this.setState({
2520 isGAuthLoading: true
2521 })
2522 const form = {
2523 token: this.state.token
2524 }
2525
2526 const header = this.props.client_manager.auth.getHeader();
2527 this.props.client_manager.service.confirmGoogleAuthToken(header, form,
2528 (res) => {
2529
2530 this.setState({
2531 isWithdrawNextOpen: true,
2532 isWithdrawNextFade: true,
2533 isWithdrawIntiFade: false,
2534 isWithdrawIntiOpen: false,
2535 isGAuthLoading: false,
2536 twoFA_error: undefined,
2537 token: undefined
2538 })
2539 },
2540 (error) => {
2541 this.setState({
2542 twoFA_error: 'Please try again.',
2543 isGAuthLoading: false,
2544 token: undefined
2545 })
2546 })
2547
2548 }
2549
2550 onSaveConfigSetting = (e) => {
2551 e.preventDefault()
2552 this.setState({
2553 isConfigSaveLoading: true
2554 })
2555 const { configVaultSelect } = this.state;
2556 const configData = {
2557 maxDailyTx: !this.state.isMaxDailyTxUnlimited ? parseInt(this.state.maxDailyTx, 10) : 1001011,
2558 maxTxHour: !this.state.isMaxTxHourUnlimited ? parseInt(this.state.maxTxHour, 10) : 1001011,
2559 maxDailyAmount: !this.state.isMaxDailyAmountUnlimited ? parseInt(this.state.maxDailyAmount, 10) : 1001011
2560 }
2561
2562 const header = this.props.client_manager.auth.getHeader();
2563 if (configVaultSelect) {
2564 if (configVaultSelect.type === 'single') {
2565
2566 /**
2567 * Add the config settings
2568 */
2569 this.props.client_manager.service.updateSingleVaultConfig(header, configVaultSelect._id, configData,
2570 (res) => {
2571 this.setState({
2572 isConfigSaveLoading: false,
2573 isConfigScreenShow: false,
2574 isConfigFade: false,
2575 isConfigOpen: false
2576 })
2577
2578 toast(<ConfigSettingsSuccessMessage />,
2579 {
2580 position: toast.POSITION.TOP_RIGHT,
2581 className: 'Toastify__toast--dark',
2582 progressClassName: 'Toastify__progress-bar--dark'
2583 }
2584 )
2585 this.props.history.push('/settings');
2586 },
2587 (error) => {
2588 if (error && error.response && error.response.status && error.response.status === 401) {
2589 this.props.history.push('/login')
2590 }
2591 this.setState({
2592 error: error.response.data.payload.message,
2593 isConfigSaveLoading: false,
2594 })
2595
2596 // toast.error('Sorry Settings not saved Please try again',
2597 // {
2598 // position: toast.POSITION.TOP_RIGHT
2599 // });
2600 })
2601
2602 } else if (configVaultSelect.type === 'shared') {
2603 this.props.client_manager.service.updateSharedVaultConfig(header, configVaultSelect._id, configData,
2604 (res) => {
2605 this.setState({
2606 isConfigSaveLoading: false,
2607 isConfigScreenShow: false,
2608 isConfigFade: false,
2609 isConfigOpen: false
2610 })
2611 toast.success('Settings updated successfully',
2612 {
2613 position: toast.POSITION.TOP_RIGHT
2614 });
2615 this.props.history.push('/settings');
2616 },
2617 (error) => {
2618 if (error && error.response && error.response.status && error.response.status === 401) {
2619 this.props.history.push('/login')
2620 }
2621 this.setState({
2622 error: error.response.data.payload.message,
2623 isConfigSaveLoading: false
2624 })
2625 toast.error('Sorry Settings not saved Please try again',
2626 {
2627 position: toast.POSITION.TOP_RIGHT
2628 });
2629 })
2630 }
2631 }
2632 }
2633
2634 async withdrawNumioIdentityAuth() {
2635 const numioCDN = new numio({ app_id: "8464920" })
2636 const res = await numioCDN.getURL()
2637
2638 this.setState({ qrUrl: res })
2639
2640 var callRes = await call(async (token) => {
2641 console.log('No-need')
2642 this.setState({ qrLoader: true })
2643 try {
2644 let body = {
2645 token: token,
2646 app_secret: "providers Secert",
2647 userDetails: ["fullname", "email", "profileImage"]
2648 }
2649
2650 let res = await axios.post("https://api-dev.numiovault.io/v1/account/numio_verify_token", body)
2651
2652 if (res.status == 201 || res.status == 200) {
2653 this.setState({
2654 isWithdrawNextOpen: true,
2655 isWithdrawNextFade: true,
2656 isWithdrawIntiFade: false,
2657 isWithdrawIntiOpen: false,
2658 isVerifiedNumio: true,
2659 isGAuthLoading: false,
2660 twoFA_error: undefined,
2661 token: undefined,
2662 qrLoader: false
2663 })
2664
2665 }
2666 else {
2667 this.setState({
2668 qrLoader: false
2669 })
2670 console.log("Error===>", res)
2671 }
2672 }
2673 catch (err) {
2674 console.log("err====>", err)
2675 }
2676
2677 })
2678
2679 }
2680
2681 closeQrModal = () => {
2682 this.setState({
2683 qrLoader: false,
2684 authmodal: false
2685 })
2686 }
2687
2688 createNewVaultWithoutAuth = () => {
2689 const vaultType = this.state.vaultType;
2690 /**
2691 * Call Generate New Single Vault API
2692 */
2693 if (vaultType === 'single') {
2694 this.generateNewVault()
2695 }
2696
2697 /**
2698 * Call Generate New Shared Vault API
2699 */
2700 if (vaultType === 'shared') {
2701 this.createSharedVault();
2702 }
2703
2704 this.setState({ isVerifiedNumio: true })
2705 }
2706
2707 onSubmitGoogleAuthTokenForAddNewVault = (e, isAutoSubmit) => {
2708 if (!isAutoSubmit) {
2709 e.preventDefault()
2710 }
2711
2712 if (!this.state.token) {
2713 this.setState({
2714 twoFA_error_addVault: 'Please enter the code from your 2FA application.',
2715 })
2716 return
2717 }
2718
2719 this.setState({
2720 isGAuthLoading: true
2721 })
2722 const form = {
2723 token: this.state.token
2724 }
2725 const { vaultType } = this.state;
2726
2727 const header = this.props.client_manager.auth.getHeader();
2728 this.props.client_manager.service.confirmGoogleAuthToken(header, form,
2729 (res) => {
2730 /**
2731 * Call Generate New Single Vault API
2732 */
2733 if (vaultType === 'single') {
2734 this.generateNewVault()
2735 }
2736
2737 /**
2738 * Call Generate New Shared Vault API
2739 */
2740 if (vaultType === 'shared') {
2741 this.createSharedVault();
2742 }
2743
2744 this.setState({
2745 twoFA_error_addVault: undefined
2746 })
2747 },
2748 (error) => {
2749 this.setState({
2750 error: error.response.data.payload.message,
2751 isGAuthLoading: false,
2752 twoFA_error_addVault: 'Please try again.'
2753 })
2754 })
2755
2756 }
2757
2758
2759 generateNewVault = () => {
2760
2761 const userDetails = this.props.client_manager.auth.getUserDetails()
2762 const form = {
2763 type: this.state.vaultType,
2764 email: userDetails.user_email,
2765 name: this.state.vaultName,
2766 currency: this.state.cryptoAsset.symbol
2767 };
2768
2769 const header = this.props.client_manager.auth.getHeader();
2770 this.props.client_manager.service.createNewVault(header, form,
2771 (res) => {
2772 /**
2773 * Call Generate New Vault API
2774 */
2775 toast(<VaultCreatedSuccessMessage />,
2776 {
2777 position: toast.POSITION.TOP_RIGHT,
2778 className: 'Toastify__toast--dark',
2779 progressClassName: 'Toastify__progress-bar--dark'
2780 }
2781 )
2782
2783 this.updateNewVaultSummary(res.data, form.currency, form.name)
2784
2785 },
2786 (error) => {
2787 this.setState({
2788 error: error.response.data.payload.message,
2789 isGAuthLoading: false
2790 })
2791 })
2792 }
2793
2794 onAddTokenToggelChange = () => {
2795 this.setState({
2796 isOpenAddTokenModal: false
2797 });
2798 }
2799
2800 addNewtoken = () => {
2801 const userDetails = this.props.client_manager.auth.getUserDetails()
2802
2803 const form = {
2804 vaultId: (userDetails && userDetails.user_vault_id) ? userDetails.user_vault_id : selectedVault._id,
2805 symbol: this.state.tokenAsset.symbol
2806 };
2807
2808 const header = this.props.client_manager.auth.getHeader();
2809 this.props.client_manager.service.createNewToken(form, header,
2810 (res) => {
2811
2812 toast(<TokenCreatedSuccessMessage />,
2813 {
2814 position: toast.POSITION.TOP_RIGHT,
2815 className: 'Toastify__toast--dark',
2816 progressClassName: 'Toastify__progress-bar--dark'
2817 }
2818 )
2819 this.setState({
2820 tokenAsset: '',
2821 isOpenAddTokenModal: true
2822 });
2823 window.location = '/dashboard'
2824
2825 },
2826 (error) => {
2827 this.setState({
2828 tokenAsset: '',
2829 isOpenAddTokenModal: true
2830 });
2831 toast(<AddTokenFailMessage error={error.response.data.payload.message} status={error.response.data.payload.statusCode} />,
2832 {
2833 position: toast.POSITION.TOP_RIGHT,
2834 className: 'Toastify__toast--dark',
2835 progressClassName: 'Toastify__progress-bar--dark-error'
2836 }
2837 )
2838 // window.location = '/dashboard'
2839 })
2840 }
2841
2842 updateNewVaultSummary(data, currency, name) {
2843 if (data) {
2844 const newVaultData = {
2845 _id: data._id ? data._id : '',
2846 balances: 0,
2847 currency: currency,
2848 name: name,
2849 type: "single",
2850 address: data.walletAddress,
2851 label: `${name} - 0 ${currency}`,
2852 value: data.walletAddress
2853 }
2854 const { optionVaults } = this.state;
2855 this.setState({
2856 newVaultSummary: {
2857 walletAddress: data.walletAddress,
2858 publicKey: data.publicKey,
2859 transactionHash: data.transactionHash,
2860 _id: data._id ? data._id : ''
2861 },
2862 isGAuthLoading: false,
2863 isSummaryPage: true,
2864 headerVaultSelect: newVaultData,
2865 optionVaults: [...optionVaults, newVaultData]
2866 })
2867
2868 this.props.dispatch(set_selected_vault(newVaultData));
2869 /**
2870 * Update VaultID state when we are selecting vault
2871 */
2872 this.props.client_manager.auth.saveUserSelectedVault(newVaultData);
2873 }
2874 }
2875
2876 onSubmitGoogleAuthTokenForSharedVault = (e) => {
2877 e.preventDefault()
2878 this.setState({
2879 isGAuthLoading: true,
2880 error: undefined
2881 })
2882 const form = {
2883 token: this.state.token
2884 }
2885
2886 const header = this.props.client_manager.auth.getHeader();
2887 this.props.client_manager.service.confirmGoogleAuthToken(header, form,
2888 (res) => {
2889 this.onStepTwoSharedVault();
2890 },
2891 (error) => {
2892 toast.error(message.GAUTH_ERROR,
2893 {
2894 position: toast.POSITION.TOP_RIGHT
2895 });
2896 this.setState({
2897 error: error.response.data.payload.message,
2898 isGAuthLoading: false
2899 })
2900 })
2901
2902 }
2903 onRedirect = (e) => {
2904 e.preventDefault();
2905 const link = e.target.attributes.to.value;
2906 this.props.history.push(link);
2907 }
2908
2909 onSelectVault = (e, headerVaultSelect) => {
2910 e.preventDefault();
2911 if (headerVaultSelect) {
2912 this.setState(
2913 {
2914 headerVaultSelect,
2915 configVaultSelect: headerVaultSelect
2916 });
2917
2918 if (headerVaultSelect.value === 'ALL VAULTS') {
2919 this.props.dispatch(set_selected_vault({}));
2920 localStorage.removeItem('user_vault_address');
2921 localStorage.removeItem('user_vault_id');
2922 localStorage.removeItem('user_vault_name');
2923 localStorage.removeItem('vault_type');
2924 localStorage.removeItem('user_vault_currency');
2925 localStorage.removeItem('user_vaults');
2926
2927 /**
2928 * Get All Vaults balance
2929 */
2930 this.getTotalBalance();
2931 /**
2932 * Get All vaults balance
2933 */
2934 this.getAllVaultBalance();
2935 /**
2936 * Get All Txns History
2937 */
2938 this.getAllTxnsHistory();
2939
2940 this.getAllGraphData();
2941 this.getCurrentUsdValue()
2942 this.getCurrentBTCValue();
2943
2944 } else {
2945
2946
2947 this.props.dispatch(set_selected_vault(headerVaultSelect));
2948 this.props.client_manager.auth.saveUserSelectedVault(headerVaultSelect);
2949 /**
2950 * Need to fetch the vault data
2951 */
2952 if (headerVaultSelect.type === 'single') {
2953 this.getSingleVaultData(headerVaultSelect)
2954 }
2955 if (headerVaultSelect.type === 'shared') {
2956 this.getSharedVaultData(undefined, headerVaultSelect)
2957 }
2958 }
2959 this.props.history.push('/dashboard');
2960 }
2961 }
2962
2963 onSelectSharedVault = (e, selectedVault) => {
2964 e.preventDefault();
2965 this.props.dispatch(set_selected_vault(selectedVault));
2966 /**
2967 * Update VaultID state when we are selecting vault
2968 */
2969 this.props.client_manager.auth.saveUserSelectedVault(selectedVault);
2970 this.props.history.push('/dashboard');
2971 }
2972
2973 onGraphFilterChange = async (e, filterVaule) => {
2974 e.preventDefault();
2975 let totalGainLossValue = 0;
2976 let totalGainLossPercentage = 0;
2977 this.setState({
2978 graphHistoryFlag: filterVaule
2979 })
2980 const { headerVaultSelect } = this.state;
2981
2982 if (headerVaultSelect && headerVaultSelect.type === 'single') {
2983 this.graphData(headerVaultSelect);
2984 } else if (headerVaultSelect && headerVaultSelect.type === 'shared') {
2985 this.sharedVaultGraphData(e, headerVaultSelect);
2986 } else {
2987 if (filterVaule) {
2988 const header = this.props.client_manager.auth.getHeader();
2989 const singleVaultGraph = await helpers.getSingleAllVaultGraph(this.props, header, filterVaule)
2990 const newGraphData = [...singleVaultGraph.data]
2991
2992 this.setState({
2993 graphData: newGraphData,
2994 filterGraphData: newGraphData,
2995 gainLossValue: singleVaultGraph.historyData ? singleVaultGraph.historyData.gainLoss : 0,
2996 gainLossPercentage: singleVaultGraph.historyData ? singleVaultGraph.historyData.gainLossPercentage : 0
2997 })
2998
2999 this.setGraphData(newGraphData)
3000 }
3001 }
3002 }
3003 /**
3004 * onSwitchVaultType
3005 */
3006 onSwitchVaultType = async (e, vaultType) => {
3007 e.preventDefault();
3008 let currentVaultType = vaultType;
3009 if (vaultType === 'all') {
3010 this.setState({
3011 currentVaultType: 'all'
3012 })
3013 } else if (vaultType === 'single') {
3014 this.setState({
3015 currentVaultType: 'single'
3016 })
3017 } else if (vaultType === 'shared') {
3018 this.setState({
3019 currentVaultType: 'shared'
3020 })
3021 }
3022
3023 const header = this.props.client_manager.auth.getHeader();
3024 if (currentVaultType === 'single') {
3025 const singleVaultBalance = await helpers.getSingleAllVaultBalance(this.props, header)
3026
3027 this.setState({
3028 vaultsBalance: singleVaultBalance.data
3029 })
3030
3031 const singleVaultTxn = await helpers.getSingleAllTxnsHistory(this.props, header)
3032 this.updateTransactionHistory('all', singleVaultTxn.data)
3033
3034 const singleVaultGraph = await helpers.getSingleAllVaultGraph(this.props, header)
3035
3036 this.setState({
3037 graphData: singleVaultGraph.data,
3038 filterGraphData: singleVaultGraph.data
3039 })
3040
3041 this.setGraphData(singleVaultGraph.data)
3042 } else if (currentVaultType === 'shared') {
3043 const sharedVaultBalance = await helpers.getSharedAllVaultBalance(this.props, header)
3044 this.setState({
3045 vaultsBalance: sharedVaultBalance.data
3046 })
3047
3048 const sharedVaultTxn = await helpers.getSharedAllTxnsHistory(this.props, header)
3049
3050 this.updateTransactionHistory('all', sharedVaultTxn.data)
3051
3052 const sharedVaultGraph = await helpers.getSharedAllVaultGraph(this.props, header)
3053
3054 this.setState({
3055 graphData: sharedVaultGraph.data,
3056 filterGraphData: sharedVaultGraph.data
3057 })
3058
3059 this.setGraphData(sharedVaultGraph.data)
3060 } else if (currentVaultType === 'all') {
3061 /**
3062 * Get All vaults balance
3063 */
3064 this.getAllVaultBalance();
3065 /**
3066 * Get All Graph Data
3067 */
3068 this.getAllGraphData();
3069 /**
3070 * Get All Txns History
3071 */
3072 this.getAllTxnsHistory();
3073 }
3074
3075 }
3076
3077 onShowSharedVaultDetails = (e, selectedVault, isRedirected) => {
3078 e.preventDefault();
3079 const header = this.props.client_manager.auth.getHeader();
3080 var vaultID = this.state.vaultsBalance[0]._id;
3081 if (selectedVault && selectedVault._id !== "undefined") {
3082 vaultID = selectedVault._id
3083 }
3084 this.props.client_manager.service.getSignersSharedVaultData(header, vaultID,
3085 (res) => {
3086 selectedVault = Object.assign(selectedVault, {
3087 signers: res.data[0].signers
3088 })
3089 this.updateSigners(selectedVault, isRedirected);
3090 },
3091 (error) => {
3092 if (error && error.response && error.response.status && error.response.status === 401) {
3093 this.props.history.push('/login')
3094 }
3095 this.setState({
3096 error: error.response.data.payload.message,
3097 isGAuthLoading: false
3098 })
3099 })
3100
3101 }
3102
3103 updateSigners = (sharedVaultDetails, isRedirected) => {
3104 this.props.dispatch(set_shared_vault_details(sharedVaultDetails));
3105 if (isRedirected) {
3106 this.props.history.push('/SharedVaultStatus');
3107 }
3108 }
3109
3110 onContinueWithdraw = (e) => {
3111 e.preventDefault();
3112
3113 const { withdrawAmount, withdrawVaultSelect, withdrawReceiver } = this.state;
3114 if (withdrawVaultSelect && withdrawVaultSelect.balances) {
3115 const availableBalance = this.state.withdrawVaultSelect.balances[0].balance;
3116 if (withdrawReceiver) {
3117 if (withdrawAmount > 0 && parseFloat(withdrawAmount) <= parseFloat(availableBalance)) {
3118 this.authtoggle();
3119 } else if (withdrawAmount > 0) {
3120 this.setState({
3121 withdrawAmount_error: 'Your amount exceeds your available balance.'
3122 })
3123 } else {
3124 this.setState({
3125 withdrawAmount_error: 'Please enter a withdraw amount.'
3126 })
3127 }
3128 } else {
3129 this.setState({
3130 withdrawReceiver_error: 'Please enter a receiver address.'
3131 })
3132 }
3133
3134 } else {
3135 this.setState({
3136 withdrawVaultSelect_error: 'Please select a Vault.'
3137 })
3138 }
3139 }
3140
3141 onOpenAuthForCreateSharedVault = (e) => {
3142 e.preventDefault();
3143 this.setState({
3144 isOpenAuthForCreateSharedVault: true
3145 })
3146 }
3147
3148 onCancelWithdraw = (e) => {
3149 e.preventDefault();
3150 this.setState({
3151 withdrawLoading: false,
3152 isWithdrawNextOpen: false,
3153 isWithdrawNextFade: false,
3154 isWithdrawIntiFade: false,
3155 isWithdrawIntiOpen: false,
3156 modal: false,
3157 fade: false,
3158 authmodal: false,
3159 authfade: false,
3160 withdrawAmount: 0,
3161 isWithdrawVerified: false,
3162 withdrawVaultSelect: undefined,
3163 withdrawReceiver: undefined
3164 })
3165 this.props.history.push('/dashboard');
3166 }
3167
3168 onCancelDeposit = (e) => {
3169 this.setState({
3170 isDepositNextFade: false,
3171 isDepositNextOpen: false,
3172 isDepositIntiFade: false,
3173 isDepositIntiOpen: false,
3174 depositVaultSelect: undefined
3175 })
3176 this.props.history.push('/dashboard');
3177 }
3178
3179 onBackFromShared = (e) => {
3180 e.preventDefault();
3181 this.props.history.push('/addNewVault');
3182 }
3183
3184 onCancelSignerStepTwo = (e) => {
3185 e.preventDefault();
3186 this.setState({
3187 isCoSignerWarningPopupEnable: false,
3188 isCoSignerWarningPopupModal: false,
3189 isCoSignerWarningPopupFade: false,
3190 })
3191 }
3192
3193 onCancelConfigSetting = (e) => {
3194 e.preventDefault();
3195 this.setState({
3196 isConfigScreenShow: false,
3197 isConfigFade: false,
3198 isConfigOpen: false
3199 })
3200 }
3201
3202 onCancelDeadManSetting = (e) => {
3203 e.preventDefault();
3204 this.setState({
3205 isShowDeadManSwitch: false,
3206 isDeadManSwitchOpen: false,
3207 isDeadManSwitchFade: false
3208 })
3209 }
3210
3211 onShowNextDepositSummary = (e) => {
3212 e.preventDefault();
3213 const { depositVaultSelect } = this.state;
3214 /**
3215 * Need to check if vault is selected or not
3216 */
3217 if (depositVaultSelect) {
3218 this.setState({
3219 isDepositNextOpen: true,
3220 isDepositNextFade: true,
3221 isDepositIntiFade: false,
3222 isDepositIntiOpen: false
3223 })
3224 } else {
3225 this.setState({
3226 depositVaultSelect_error: 'Please select a Vault.'
3227 })
3228 }
3229 }
3230
3231 toggle = async () => {
3232 await this.setState({
3233 modal: !this.state.modal,
3234 fade: !this.state.fade,
3235 isWithdrawVerified: !this.state.isWithdrawVerified
3236 });
3237 }
3238
3239 authtoggle = async () => {
3240 await this.setState({
3241 authmodal: !this.state.authmodal,
3242 authfade: !this.state.authfade,
3243 isWithdrawVerified: !this.state.isWithdrawVerified
3244 });
3245 }
3246
3247 coSignerAuthToggle = () => {
3248 this.setState({
3249 coSignerAuthModal: !this.state.coSignerAuthModal,
3250 coSignerAuthFade: !this.state.coSignerAuthFade,
3251 });
3252 }
3253
3254 onCloseDeposit = (e) => {
3255 e.preventDefault();
3256 this.setState({
3257 isDepositNextOpen: false,
3258 isDepositNextFade: false,
3259 isDepositIntiFade: false,
3260 isDepositIntiOpen: false,
3261 depositVaultSelect: undefined
3262 })
3263 this.props.history.push('/dashboard');
3264 }
3265
3266 onBackDeposit = (e) => {
3267 e.preventDefault();
3268 this.setState({
3269 isDepositNextOpen: false,
3270 isDepositNextFade: false,
3271 isDepositIntiFade: true,
3272 isDepositIntiOpen: true
3273 })
3274 }
3275
3276 onBackWithdraw = (e) => {
3277 e.preventDefault();
3278 this.setState({
3279 isWithdrawNextOpen: false,
3280 isWithdrawNextFade: false,
3281 isWithdrawIntiFade: true,
3282 isWithdrawIntiOpen: true,
3283 token: undefined
3284 })
3285 this.authtoggle()
3286 }
3287
3288 onCloseSendaPaymentModal = () => {
3289 this.setState({ isOpenSendaPaymentModal: false })
3290 }
3291
3292 onCloseAddRecipientModal = () => {
3293 this.setState({ isOpenAddRecipientModal: false })
3294 }
3295
3296 onCloseSuccessModal = () => {
3297 this.setState({ isOpenSuccessModal: false })
3298 }
3299
3300 onContinueSendaPaymentModal = () => {
3301 this.setState({
3302 isOpenSendaPaymentModal: true,
3303 isOpenAddRecipientModal: false,
3304 isOpenSuccessModal: false
3305 })
3306
3307 }
3308
3309 onContinueAddRecipientModal = () => {
3310 this.setState({
3311 isOpenSendaPaymentModal: false,
3312 isOpenAddRecipientModal: true,
3313 isOpenSuccessModal: false
3314 })
3315
3316 }
3317
3318 onContinueSuccessModal = () => {
3319 this.setState({
3320 isOpenSendaPaymentModal: false,
3321 isOpenAddRecipientModal: false,
3322 isOpenSuccessModal: true
3323 })
3324
3325 }
3326
3327 onCopied = (e) => {
3328 e.preventDefault();
3329 this.setState({
3330 isCopied: true
3331 })
3332 }
3333
3334 onShowDeadManSwitchUI = (e) => {
3335 e.preventDefault();
3336 this.setState({
3337 isShowDeadManSwitch: true,
3338 isDeadManSwitchOpen: true,
3339 isDeadManSwitchFade: true,
3340 })
3341 }
3342
3343 onSubmitWithdraw = (e) => {
3344 e.preventDefault();
3345 /**
3346 * API call to submit withdraw transaction
3347 */
3348 this.setState({
3349 withdrawLoading: true
3350 })
3351 let { withdrawReceiver, withdrawAmount, withdrawVaultSelect, allTempTransactions } = this.state;
3352
3353 if (withdrawVaultSelect.type === 'shared') {
3354
3355 const form = {
3356 receiver: withdrawReceiver,
3357 amount: parseFloat(scientificToDecimal(withdrawAmount)),
3358 symbol: withdrawVaultSelect ? withdrawVaultSelect.currency : 'ETH',
3359 vault_name: withdrawVaultSelect.name
3360 }
3361 const header = this.props.client_manager.auth.getHeader();
3362 const vaultID = this.state.selectedVault ? this.state.selectedVault._id : this.state.vaults[0]._id;
3363 this.props.client_manager.service.sharedVaultWithdrawAPI(
3364 header,
3365 form,
3366 vaultID,
3367 (data) => {
3368 const newTxnsData = {
3369 from: withdrawVaultSelect.address,
3370 to: form.receiver,
3371 amount: parseFloat(form.amount),
3372 coin_price: 0,
3373 coin_price_btc: 0,
3374 _id: "",
3375 vault: { type: withdrawVaultSelect.type, _id: withdrawVaultSelect._id, name: withdrawVaultSelect.name },
3376 user: "",
3377 transaction_type: "withdraw",
3378 transaction_hash: "",
3379 status: "pending",
3380 token: form.symbol,
3381 timestamp: moment().toISOString()
3382 }
3383
3384 allTempTransactions.push(newTxnsData)
3385
3386 this.setState({
3387 withdrawLoading: false,
3388 allTempTransactions: allTempTransactions,
3389 isWithdrawNextOpen: false,
3390 isWithdrawNextFade: false,
3391 isWithdrawIntiFade: false,
3392 isWithdrawIntiOpen: false,
3393 isOpenSendaPaymentModal: false,
3394 isOpenAddRecipientModal: false,
3395 isOpenSuccessModal: false,
3396 modal: false,
3397 fade: false,
3398 authmodal: false,
3399 authfade: false,
3400 withdrawAmount: 0,
3401 isWithdrawVerified: false,
3402 withdrawVaultSelect: undefined,
3403 withdrawReceiver: undefined
3404 })
3405
3406 toast.success(<WithdrawSuccessMessage />,
3407 {
3408 position: toast.POSITION.TOP_RIGHT,
3409 className: 'Toastify__toast--dark',
3410 progressClassName: 'Toastify__progress-bar--dark'
3411 });
3412 this.props.history.push('/dashboard');
3413 },
3414 (error) => {
3415 toast(<WithdrawFailMessage error={error.response.data.payload.message} status={error.response.data.payload.statusCode} />,
3416 {
3417 position: toast.POSITION.TOP_RIGHT,
3418 className: 'Toastify__toast--dark',
3419 progressClassName: 'Toastify__progress-bar--dark-error'
3420 }
3421 )
3422
3423 this.setState({
3424 withdrawLoading: false,
3425 withdrawError: message.WITHDRAW_TRANSACTION_FAILD,
3426 isWithdrawNextOpen: false,
3427 isWithdrawNextFade: false,
3428 isWithdrawIntiFade: false,
3429 isWithdrawIntiOpen: false,
3430 withdrawVaultSelect: undefined,
3431 modal: false,
3432 fade: false,
3433 authmodal: false,
3434 authfade: false,
3435 withdrawAmount: 0,
3436 isWithdrawVerified: false,
3437 withdrawReceiver: undefined
3438 })
3439 });
3440 } else {
3441 this.setState({
3442 withdrawLoading: true
3443 })
3444
3445 const form = {
3446 receiver: withdrawReceiver,
3447 amount: parseFloat(scientificToDecimal(withdrawAmount)),
3448 symbol: withdrawVaultSelect ? withdrawVaultSelect.balances[0].currency : 'ETH'
3449 }
3450 const header = this.props.client_manager.auth.getHeader();
3451 const vaultID = this.state.selectedVault ? this.state.selectedVault._id : this.state.vaults[0]._id;
3452 this.props.client_manager.service.withdrawCryptoAPI(
3453 header,
3454 form,
3455 vaultID,
3456 (data) => {
3457 const newTxnsData = {
3458 from: withdrawVaultSelect.address,
3459 to: form.receiver,
3460 amount: parseFloat(form.amount),
3461 _id: "temp",
3462 vault: { type: withdrawVaultSelect.type, _id: withdrawVaultSelect._id },
3463 user: "",
3464 transaction_type: "withdraw",
3465 transaction_hash: "",
3466 status: "pending",
3467 token: form.symbol,
3468 timestamp: moment().toISOString()
3469 }
3470 allTempTransactions.push(newTxnsData)
3471
3472 this.setState({
3473 withdrawLoading: false,
3474 allTempTransactions: allTempTransactions,
3475 isWithdrawNextOpen: false,
3476 isWithdrawNextFade: false,
3477 isWithdrawIntiFade: false,
3478 isWithdrawIntiOpen: false,
3479 modal: false,
3480 fade: false,
3481 authmodal: false,
3482 authfade: false,
3483 withdrawAmount: 0,
3484 isWithdrawVerified: false,
3485 withdrawVaultSelect: undefined,
3486 withdrawReceiver: undefined
3487 })
3488 toast.success(<WithdrawSuccessMessage />,
3489 {
3490 position: toast.POSITION.TOP_RIGHT,
3491 className: 'Toastify__toast--dark',
3492 progressClassName: 'Toastify__progress-bar--dark'
3493 });
3494 this.props.history.push('/dashboard');
3495 },
3496 (error) => {
3497 toast(<WithdrawFailMessage error={error.response.data.payload.message} status={error.response.data.payload.statusCode} />,
3498 {
3499 position: toast.POSITION.TOP_RIGHT,
3500 className: 'Toastify__toast--dark',
3501 progressClassName: 'Toastify__progress-bar--dark-error'
3502 }
3503 )
3504
3505 this.setState({
3506 withdrawLoading: false,
3507 withdrawError: message.WITHDRAW_TRANSACTION_FAILD,
3508 isWithdrawNextOpen: false,
3509 isWithdrawNextFade: false,
3510 isWithdrawIntiFade: false,
3511 isWithdrawIntiOpen: false,
3512 withdrawVaultSelect: undefined,
3513 modal: false,
3514 fade: false,
3515 authmodal: false,
3516 authfade: false,
3517 withdrawAmount: 0,
3518 isWithdrawVerified: false,
3519 withdrawReceiver: undefined
3520 })
3521 });
3522 }
3523 }
3524
3525 handleWithdrawVaultSelect = withdrawVaultSelect => {
3526 if (withdrawVaultSelect) {
3527 this.props.dispatch(set_selected_vault(withdrawVaultSelect));
3528
3529 this.setState(
3530 {
3531 withdrawVaultSelect,
3532 selectedVault: withdrawVaultSelect,
3533 withdrawSymbol: withdrawVaultSelect.currency,
3534 withdrawVaultSelect_error: undefined
3535
3536 }
3537 );
3538 this.props.client_manager.auth.saveUserSelectedVault(withdrawVaultSelect);
3539 }
3540
3541 };
3542
3543 handleDepositVaultSelect = depositVaultSelect => {
3544 if (depositVaultSelect) {
3545
3546 this.props.dispatch(set_selected_vault(depositVaultSelect));
3547 this.setState(
3548 {
3549 depositVaultSelect,
3550 depositVaultSelect_error: undefined
3551 });
3552 this.props.client_manager.auth.saveUserSelectedVault(depositVaultSelect);
3553 }
3554 };
3555 /**
3556 * Handle and update the data on selecting header vault
3557 */
3558 handleHeaderVaultSelect = async (headerVaultSelect) => {
3559 if (headerVaultSelect) {
3560 this.setState(
3561 {
3562 headerVaultSelect,
3563 configVaultSelect: headerVaultSelect,
3564 vaultsBalance: [],
3565 totalBalance: 0,
3566 graphData: [],
3567 filterGraphData: [],
3568 graphDataWithLabels: [],
3569 gainLossValue: 0,
3570 gainLossPercentage: 0
3571 });
3572
3573 if (headerVaultSelect.value === 'ALL VAULTS') {
3574 this.props.dispatch(set_selected_vault({}));
3575 localStorage.removeItem('user_vault_address');
3576 localStorage.removeItem('user_vault_id');
3577 localStorage.removeItem('user_vault_name');
3578 localStorage.removeItem('vault_type');
3579 localStorage.removeItem('user_vault_currency');
3580 localStorage.removeItem('user_vaults');
3581
3582 /**
3583 * Get All Vaults balance
3584 */
3585 this.getTotalBalance();
3586 /**
3587 * Get All vaults balance
3588 */
3589 this.getAllVaultBalance();
3590 /**
3591 * Get All Txns History
3592 */
3593 this.getAllTxnsHistory();
3594
3595 this.getAllGraphData();
3596 this.getCurrentUsdValue()
3597 this.getCurrentBTCValue();
3598
3599 } else {
3600
3601
3602 this.props.dispatch(set_selected_vault(headerVaultSelect));
3603 this.props.client_manager.auth.saveUserSelectedVault(headerVaultSelect);
3604 /**
3605 * Need to fetch the vault data
3606 */
3607 if (headerVaultSelect.type === 'single') {
3608 this.getSingleVaultData(headerVaultSelect)
3609 }
3610 if (headerVaultSelect.type === 'shared') {
3611 this.getSharedVaultData(undefined, headerVaultSelect)
3612 }
3613 }
3614 }
3615 }
3616
3617 /**
3618 * Handle and update the data on selecting header vault
3619 */
3620 handleDashboardVaultSelect = async (e, headerVaultSelect) => {
3621 e.preventDefault();
3622
3623 if (headerVaultSelect) {
3624 headerVaultSelect.label = `${headerVaultSelect.name.slice(0, 30)} - ${getFormattedNumber(headerVaultSelect.balances)} ${headerVaultSelect.currency}`
3625 this.setState(
3626 {
3627 headerVaultSelect,
3628 configVaultSelect: headerVaultSelect
3629 });
3630
3631 this.props.dispatch(set_selected_vault(headerVaultSelect));
3632 this.props.client_manager.auth.saveUserSelectedVault(headerVaultSelect);
3633 /**
3634 * Need to fetch the vault data
3635 */
3636 if (headerVaultSelect.type === 'single') {
3637 this.getSingleVaultData(headerVaultSelect)
3638 }
3639 if (headerVaultSelect.type === 'shared') {
3640 this.getSharedVaultData(undefined, headerVaultSelect)
3641 }
3642
3643 }
3644 }
3645
3646 handleConfigVaultSelect = async (configVaultSelect) => {
3647 if (configVaultSelect && configVaultSelect.address) {
3648 this.setState(
3649 {
3650 configVaultSelect,
3651 });
3652
3653 /**
3654 * Update the selected vault on main level
3655 */
3656 this.props.dispatch(set_selected_vault(configVaultSelect));
3657 this.props.client_manager.auth.saveUserSelectedVault(configVaultSelect);
3658 this.handleHeaderVaultSelect(configVaultSelect);
3659 /**
3660 * 1. Fetch config setting
3661 * 2. Fetch whitelist setting
3662 */
3663 const header = this.props.client_manager.auth.getHeader();
3664 const vaultID = configVaultSelect._id;
3665 var configSettings;
3666 var whitelistData;
3667
3668 if (configVaultSelect && configVaultSelect.type === 'single') {
3669 configSettings = await helpers.getConfigDataForSingleVault(this.props, header, vaultID);
3670 whitelistData = await helpers.getWhitelistDataforSingleVault(this.props, header, vaultID);
3671 } else if (configVaultSelect && configVaultSelect.type === 'shared') {
3672 configSettings = await helpers.getConfigDataForSharedVaultData(this.props, header, vaultID);
3673 whitelistData = await helpers.getWhitelistDataforSharedVault(this.props, header, vaultID)
3674 }
3675 if (whitelistData && whitelistData.data && whitelistData.data.length > 0) {
3676 whitelistData = whitelistData.data.map((whitelistUser) => {
3677 return {
3678 whitelistId: whitelistUser._id,
3679 vaultId: whitelistUser.vaultId,
3680 whitelistUserName: whitelistUser.name,
3681 whitelistUserEmail: whitelistUser.email,
3682 whitelistUserAddress: whitelistUser.address
3683 }
3684 })
3685 this.setState(
3686 {
3687 whiteListUsersData: whitelistData,
3688 // isUpdateWhitelistAvailable: true
3689 })
3690 } else {
3691 this.setState(
3692 {
3693 whiteListUsersData: []
3694 })
3695 }
3696
3697 if (configSettings && configSettings.success) {
3698 this.setState(
3699 {
3700 maxDailyAmount: configSettings.data.maxDailyAmount.toString().length > 6 ? 0 : configSettings.data.maxDailyAmount,
3701 maxDailyTx: configSettings.data.maxDailyTx.toString().length > 6 ? 0 : configSettings.data.maxDailyTx,
3702 maxTxHour: configSettings.data.maxTxHour.toString().length > 6 ? 0 : configSettings.data.maxTxHour,
3703 isMaxDailyTxUnlimited: configSettings.data.maxDailyTx.toString().length > 6 ? true : false,
3704 isMaxDailyAmountUnlimited: configSettings.data.maxDailyAmount.toString().length > 6 ? true : false,
3705 isMaxTxHourUnlimited: configSettings.data.maxTxHour.toString().length > 6 ? true : false,
3706 });
3707 }
3708 }
3709 };
3710
3711 handleRangeFilter = selectedRangeFilter => {
3712 this.setState(
3713 { selectedRangeFilter }
3714 );
3715 };
3716
3717 onInputChange = (e) => {
3718 const key = e.target.id;
3719 this.setState({
3720 [key]: e.target.value
3721 }, () => {
3722 if (this.state.token && this.state.token.length === 6) {
3723 this.onSubmitGoogleAuthToken(e, true)
3724 }
3725 })
3726 }
3727
3728 onInputWhitelistChange = (e) => {
3729 const key = e.target.id;
3730 if (key === 'whitelistUserName') {
3731 this.setState({
3732 [key]: e.target.value,
3733 whitelistUserName_error: undefined
3734 }, () => {
3735 })
3736 }
3737 if (key === 'whitelistUserEmail') {
3738 // Check is email valid or invalid
3739 const isValidEmail = isEmail(e.target.value);
3740 if (isValidEmail) {
3741 this.setState({
3742 [key]: e.target.value,
3743 whitelistUserEmail_error: undefined
3744 }, () => {
3745 })
3746 } else {
3747 this.setState({
3748 [key]: e.target.value,
3749 whitelistUserEmail_error: 'Please enter a valid Email Address.'
3750 }, () => {
3751 })
3752 }
3753
3754 }
3755 if (key === 'whitelistUserAddress') {
3756 this.setState({
3757 [key]: e.target.value,
3758 whitelistUserAddress_error: undefined
3759 }, () => {
3760 })
3761 }
3762
3763 }
3764
3765 onFlagUpdateForConfig = (e) => {
3766 const key = e.target.id
3767 this.setState({
3768 [key]: !this.state[key]
3769 })
3770 }
3771
3772 showConfigScreen = (e) => {
3773 e.preventDefault();
3774 window.location = './settings'
3775 // this.setState({
3776 // isConfigScreenShow: true,
3777 // isConfigOpen: true,
3778 // isConfigFade: true
3779 // })
3780 }
3781
3782 handleWithdrawAddress = (e) => {
3783 if (e.target.value) {
3784 this.setState({
3785 withdrawReceiver: e.target.value,
3786 withdrawReceiver_error: undefined
3787 })
3788 } else {
3789 this.setState({
3790 withdrawReceiver: undefined,
3791 withdrawReceiver_error: 'Please enter a receiver address.'
3792 })
3793 }
3794 }
3795
3796 handleWithdrawAmount = (e, hightAmount) => {
3797
3798 const targetValue = e.target.value;
3799 // e.target.value = e.target.value.replace(/^0+/, '')
3800 const key = e.target.id;
3801 if (e.target.value) {
3802 if (Number(e.target.value) >= Number(hightAmount)) {
3803 this.setState({
3804 [key]: e.target.value,
3805 withdrawAmount_error: 'Your amount exceeds your available balance.'
3806 })
3807 } else {
3808 this.setState({
3809 [key]: e.target.value,
3810 withdrawAmount_error: undefined
3811 })
3812 }
3813
3814 } else if (targetValue === '0.') {
3815 this.setState({
3816 [key]: targetValue,
3817 withdrawAmount_error: undefined
3818 })
3819 } else if (!e.target.value) {
3820 this.setState({
3821 [key]: '',
3822 withdrawAmount_error: undefined
3823 })
3824 }
3825 }
3826
3827 handleWithdrawAssetChange = async (withdrawSymbol) => {
3828 this.setState(
3829 { withdrawSymbol }
3830 );
3831 };
3832
3833 handleSortFilter = async (selectedSortFilter) => {
3834 this.setState(
3835 { selectedSortFilter }
3836 );
3837
3838 let { filterAllVaults, allVaults } = this.state;
3839
3840 if (selectedSortFilter.value === 'highestBalance') {
3841
3842 filterAllVaults = _.orderBy(allVaults, ['balances'], ['desc']);
3843 this.setState(
3844 { filterAllVaults }
3845 );
3846 } else {
3847 filterAllVaults = _.orderBy(allVaults, ['balances'], ['asc']);
3848 this.setState(
3849 { filterAllVaults }
3850 );
3851 }
3852 };
3853
3854 onRemoveCoSigner = (e, signer) => {
3855 e.preventDefault();
3856 var { sharedVaultData_coSignerData } = this.state;
3857 sharedVaultData_coSignerData = sharedVaultData_coSignerData.filter((thread) => {
3858 return thread.toLowerCase() !== signer.toLowerCase()
3859 })
3860 this.setState({
3861 sharedVaultData_coSignerData: sharedVaultData_coSignerData
3862 });
3863 }
3864
3865 handleChangeStartDatePicker = date => {
3866 this.setState({
3867 startDate: date
3868 });
3869 const { endDate } = this.state;
3870 this.filterTransactionHistoryOnDateChange(date, endDate);
3871 };
3872
3873 handleChangeEndDatePicker = date => {
3874 this.setState({
3875 endDate: date
3876 });
3877 const { startDate } = this.state;
3878 this.filterTransactionHistoryOnDateChange(startDate, date);
3879 };
3880
3881 handleDeadManTimeFrame = (timeFrame) => {
3882 this.setState({
3883 selectdDeadManTimeFrame: timeFrame
3884 })
3885 }
3886
3887 handleWAEFDeadManSwtich = (e) => {
3888 e.preventDefault()
3889 this.setState({
3890 isDeadManSwitchWalletAddressEnable: true
3891 })
3892 }
3893
3894 handleDeadManTime = (e) => {
3895 e.preventDefault()
3896 const { selectdDeadManTimeFrame } = this.state;
3897 if (selectdDeadManTimeFrame.value === 'day') {
3898 if (parseInt(e.target.value, 10) <= 30 && parseInt(e.target.value, 10) >= 0) {
3899 this.setState({
3900 deadManTime: e.target.value
3901 })
3902 }
3903
3904 } else if (selectdDeadManTimeFrame.value === 'month') {
3905 if (parseInt(e.target.value, 10) <= 12 && parseInt(e.target.value, 10) >= 0) {
3906 this.setState({
3907 deadManTime: e.target.value
3908 })
3909 }
3910 } else if (selectdDeadManTimeFrame.value === 'year') {
3911 if (parseInt(e.target.value, 10) >= 0) {
3912 this.setState({
3913 deadManTime: e.target.value
3914 })
3915 }
3916
3917 }
3918 }
3919
3920 filterTransactionHistoryOnDateChange = (startDate, endDate) => {
3921
3922 let { filterTransactionHistory, allTransactionHistory, allTempTransactions } = this.state;
3923 /**
3924 * Filter the transaction history according to date range
3925 */
3926 if (allTransactionHistory.length > 0) {
3927 filterTransactionHistory = allTransactionHistory.filter((transaction, idx) => {
3928 return (moment(transaction.timestamp) > moment(startDate) && moment(transaction.timestamp) < moment(endDate))
3929 });
3930 filterTransactionHistory = _.orderBy(filterTransactionHistory, ['timestamp'], ['desc']);
3931
3932 allTempTransactions = allTempTransactions.filter((thread) => {
3933 const checkTxn = _.some(filterTransactionHistory, { 'amount': thread.amount, 'from': thread.from, 'to': thread.to, 'token': thread.token });
3934 if (!checkTxn) {
3935 return thread
3936 }
3937 })
3938
3939 this.setState({
3940 filterTransactionHistory: filterTransactionHistory,
3941 allTempTransactions: allTempTransactions
3942 })
3943 }
3944 }
3945
3946 render() {
3947 return <FullLayout
3948 onRedirect={this.onRedirect}
3949 onSubmit={this.onSubmit}
3950 onInputChange={this.onInputChange}
3951 onFilterTransactions={this.onFilterTransactions}
3952 onSelectVault={this.onSelectVault}
3953 handleOnChangeSlider={this.handleOnChangeSlider}
3954 onSelectSharedVault={this.onSelectSharedVault}
3955 onShowSharedVaultDetails={this.onShowSharedVaultDetails}
3956 onContinueWithdraw={this.onContinueWithdraw}
3957 onCreateAccountModal1={this.onCreateAccountModal1}
3958 onCreateAccountModal2={this.onCreateAccountModal2}
3959 onCreateAccountModal3={this.onCreateAccountModal3}
3960 onCancelWithdraw={this.onCancelWithdraw}
3961 onCloseDeposit={this.onCloseDeposit}
3962 onSubmitAddVault={this.onSubmitAddVault}
3963 onSubmitAddToken={this.onSubmitAddToken}
3964 onSubmitWithdraw={this.onSubmitWithdraw}
3965 handleWithdrawVaultSelect={this.handleWithdrawVaultSelect}
3966 handleDepositVaultSelect={this.handleDepositVaultSelect}
3967 handleWithdrawAssetChange={this.handleWithdrawAssetChange}
3968 handleWithdrawAmount={this.handleWithdrawAmount}
3969 handleToken={this.handleToken}
3970 onShowNextDepositSummary={this.onShowNextDepositSummary}
3971 handleRangeFilter={this.handleRangeFilter}
3972 onShowDeadManSwitchUI={this.onShowDeadManSwitchUI}
3973 handleSortFilter={this.handleSortFilter}
3974 handleChangeStartDatePicker={this.handleChangeStartDatePicker}
3975 handleChangeEndDatePicker={this.handleChangeEndDatePicker}
3976 onSubmitGoogleAuthToken={this.onSubmitGoogleAuthToken}
3977 onOpenAuthForCreateSharedVault={this.onOpenAuthForCreateSharedVault}
3978 onCopied={this.onCopied}
3979 onBackWithdraw={this.onBackWithdraw}
3980 onCloseSendaPaymentModal={this.onCloseSendaPaymentModal}
3981 onCloseAddRecipientModal={this.onCloseAddRecipientModal}
3982 onCloseSuccessModal={this.onCloseSuccessModal}
3983 onContinueSendaPaymentModal={this.onContinueSendaPaymentModal}
3984 onContinueAddRecipientModal={this.onContinueAddRecipientModal}
3985 onContinueSuccessModal={this.onContinueSuccessModal}
3986 onSideBarChanged={this.onSideBarChanged}
3987 handleSharedVaultName={this.handleSharedVaultName}
3988 handleCryptoSelectForSharedVault={this.handleCryptoSelectForSharedVault}
3989 handleSharedVaultEmailCurrentCoSigner={this.handleSharedVaultEmailCurrentCoSigner}
3990 handleAddCoSignerCountAndData={this.handleAddCoSignerCountAndData}
3991 handleAddWhitelistUsers={this.handleAddWhitelistUsers}
3992 handleNextAllowedWhitelistUserAdd={this.handleNextAllowedWhitelistUserAdd}
3993 handleCryptoAssetChange={this.handleCryptoAssetChange}
3994 handleTokenAssetChange={this.handleTokenAssetChange}
3995 onStepTwoSharedVault={this.onStepTwoSharedVault}
3996 onStepThreeSharedVault={this.onStepThreeSharedVault}
3997 onCancelSignerStepTwo={this.onCancelSignerStepTwo}
3998 onSubmitGoogleAuthTokenForSharedVault={this.onSubmitGoogleAuthTokenForSharedVault}
3999 onRemoveCoSigner={this.onRemoveCoSigner}
4000 onSwitchVaultType={this.onSwitchVaultType}
4001 onSubmitGoogleAuthTokenForAddNewVault={this.onSubmitGoogleAuthTokenForAddNewVault}
4002 onCloseAction={this.onCloseAction}
4003 getSingleVaultData={this.getSingleVaultData}
4004 getTxnsForSingleHistory={this.getTxnsForSingleHistory}
4005 handleVaultName={this.handleVaultName}
4006 onBackFromShared={this.onBackFromShared}
4007 getFilteredVaults={this.getFilteredVaults}
4008 onChangeVaultType={this.onChangeVaultType}
4009 onFilterTransactionsByVault={this.onFilterTransactionsByVault}
4010 getSharedVaultData={this.getSharedVaultData}
4011 handleConfigVaultSelect={this.handleConfigVaultSelect}
4012 handleHeaderVaultSelect={this.handleHeaderVaultSelect}
4013 showConfigScreen={this.showConfigScreen}
4014 handleUpdateWhitelistUser={this.handleUpdateWhitelistUser}
4015 onCancelConfigSetting={this.onCancelConfigSetting}
4016 onSaveConfigSetting={this.onSaveConfigSetting}
4017 onCancelDeadManSetting={this.onCancelDeadManSetting}
4018 onFlagUpdateForConfig={this.onFlagUpdateForConfig}
4019 handleDeadManTimeFrame={this.handleDeadManTimeFrame}
4020 handleDeadManTime={this.handleDeadManTime}
4021 handleWAEFDeadManSwtich={this.handleWAEFDeadManSwtich}
4022 handleUpdateWhitelistUserInput={this.handleUpdateWhitelistUserInput}
4023 onGraphFilterChange={this.onGraphFilterChange}
4024 uploadPhotoChange={this.uploadPhotoChange}
4025 onBackDeposit={this.onBackDeposit}
4026 handleWithdrawAddress={this.handleWithdrawAddress}
4027 onInputWhitelistChange={this.onInputWhitelistChange}
4028 getVaultNotifications={this.getVaultNotifications}
4029 onCloseActionAddVault2FA={this.onCloseActionAddVault2FA}
4030 toggle={this.toggle}
4031 authtoggle={this.authtoggle}
4032 onCloseDeposit={this.onCloseDeposit}
4033 withdrawNumioIdentityAuth={this.withdrawNumioIdentityAuth}
4034 closeQrModal={this.closeQrModal}
4035 onCloseWithdrawAction={this.onCloseWithdrawAction}
4036 handleDashboardVaultSelect={this.handleDashboardVaultSelect}
4037 updateNotificationReadStatus={this.updateNotificationReadStatus}
4038 getAllTokens={this.getAllTokens}
4039 onAddTokenToggelChange={this.onAddTokenToggelChange}
4040 {...this.state}
4041 {...this.props}
4042 />
4043 }
4044}
4045
4046function mapStatestoProps(state) {
4047 return {
4048 vaultData: state.registration.vaultData,
4049 sharedVaultDetails: state.registration.sharedVaultDetails
4050 }
4051}
4052
4053export const DashboardContainer = withRouter(connect(mapStatestoProps)(_DashboardContainer));
4054