-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement application bootstrap component #4815
Changes from 13 commits
e0b6708
28ebb35
2b4dd09
1d35985
dd1c8f2
a22ca88
d2694f2
b266fbd
5c78a64
85360ed
133fb96
b66e55f
ffca466
7e6c2c3
49db6ec
bb8e94d
e01ac85
f6faee1
8c3b308
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ const config = { | |
new webpack.DefinePlugin({ | ||
PRODUCTION: JSON.stringify(false), | ||
VERSION: JSON.stringify(version), | ||
DEFAULT_NETWORK: 'devnet', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no iots wront its should be in .env |
||
}), | ||
], | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { useEffect } from 'react'; | ||
import { | ||
useGetDefaultApplication, | ||
useApplicationManagement, | ||
useCurrentApplication, | ||
} from '@blockchainApplication/manage/hooks'; | ||
import { useTransactionUpdate } from '@transaction/hooks'; | ||
import { PrimaryButton } from 'src/theme/buttons'; | ||
|
||
const ApplicationBootstrap = ({ children }) => { | ||
const { | ||
applications: defaultApps = [], | ||
isFetched, | ||
error, | ||
isLoading, | ||
retry, | ||
} = useGetDefaultApplication(); | ||
const { setApplications } = useApplicationManagement(); | ||
const [, setCurrentApplication] = useCurrentApplication(); | ||
|
||
useTransactionUpdate(); | ||
|
||
useEffect(() => { | ||
if (defaultApps.length && isFetched) { | ||
setCurrentApplication(defaultApps[0]); | ||
setApplications(defaultApps); | ||
} | ||
}, [isFetched]); | ||
|
||
if (error) { | ||
// @TODO: this return should be replaced with an actual error message page | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. create a ticket if is not exist and add ticket number to todo |
||
return ( | ||
<div> | ||
error | ||
<PrimaryButton onClick={retry}>Retry</PrimaryButton> | ||
</div> | ||
); | ||
} | ||
|
||
return !isLoading && isFetched ? children : null; | ||
}; | ||
|
||
export default ApplicationBootstrap; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,58 @@ | ||
import { useCallback, useMemo } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { addApplication, deleteApplication } from '../store/action'; | ||
import { addApplication, deleteApplication, setApplications as setApps } from '../store/action'; | ||
import { selectApplications } from '../store/selectors'; | ||
import { useCurrentApplication } from './useCurrentApplication'; | ||
import { usePinBlockchainApplication } from './usePinBlockchainApplication'; | ||
import { useBlockchainApplicationMeta } from './queries/useBlockchainApplicationMeta'; | ||
import { useApplicationExploreAndMetaData } from './useApplicationExploreAndMetaData'; | ||
|
||
// eslint-disable-next-line max-statements | ||
export function useApplicationManagement() { | ||
const dispatch = useDispatch(); | ||
const [currentApplication, setCurrentApplication] = useCurrentApplication(); | ||
const {data: defaultApplications} = useBlockchainApplicationMeta() | ||
const { applications: defaultApplications } = useApplicationExploreAndMetaData(); | ||
|
||
const { checkPinByChainId, pins } = usePinBlockchainApplication(); | ||
const applicationsObject = useSelector(selectApplications); | ||
const applications = useMemo( | ||
() => { | ||
const appsList = Object.values(applicationsObject); | ||
return appsList.map((app) => ({ | ||
const applications = useMemo(() => { | ||
const appsList = Object.values(applicationsObject); | ||
return appsList | ||
.map((app) => ({ | ||
...app, | ||
isPinned: checkPinByChainId(app.chainID), | ||
})).sort((a) => (a.isPinned ? -1 : 1)); | ||
}, | ||
[applicationsObject, pins], | ||
); | ||
})) | ||
.sort((a) => (a.isPinned ? -1 : 1)); | ||
}, [applicationsObject, pins]); | ||
|
||
const setApplication = useCallback( | ||
(application) => { | ||
if (application.isDefault) return; | ||
dispatch(addApplication(application)); | ||
}, | ||
[], | ||
); | ||
const setApplication = useCallback((application) => { | ||
if (application.isDefault) return; | ||
dispatch(addApplication(application)); | ||
}, []); | ||
|
||
const setApplications = (apps) => { | ||
dispatch(setApps(apps)); | ||
}; | ||
|
||
const getApplicationByChainId = useCallback( | ||
(chainId) => applications.find((app) => app.chainID === chainId), | ||
[applications], | ||
); | ||
|
||
const deleteApplicationByChainId = useCallback( | ||
(chainId) => { | ||
dispatch(deleteApplication(chainId)); | ||
if (currentApplication.chainID === chainId) { | ||
// Set Lisk as default if application in use is being deleted | ||
setCurrentApplication(defaultApplications.data[0]); | ||
} | ||
}, | ||
[], | ||
[applications] | ||
); | ||
|
||
const deleteApplicationByChainId = useCallback((chainId) => { | ||
if (currentApplication.isDefault) return; | ||
|
||
dispatch(deleteApplication(chainId)); | ||
if (currentApplication.chainID === chainId) { | ||
// Set Lisk as default if application in use is being deleted | ||
setCurrentApplication(defaultApplications[0]); | ||
} | ||
}, []); | ||
|
||
return { | ||
applications, setApplication, getApplicationByChainId, deleteApplicationByChainId, | ||
applications, | ||
setApplication, | ||
setApplications, | ||
getApplicationByChainId, | ||
deleteApplicationByChainId, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment not related to this file
Question: This seems to be unrelated to hardware wallet? Shouldnt we merge this into development?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eniola its wrong env you can have .env file in your pc for test propose check this out
https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used