-
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e0b6708
feature: fimplemented bootstrap component
eniolam1000752 28ebb35
fix: resolved all client issues faced
eniolam1000752 2b4dd09
Merge branch 'feature/adapt-hw' into 4707-application-bootstrap
eniolam1000752 1d35985
fix: resolved deepscan issues
eniolam1000752 dd1c8f2
fix: merged from remote
eniolam1000752 a22ca88
fix: resolved failing test on useCurrentApplication
eniolam1000752 d2694f2
fix: resolved failing test on useApplicationManagement
eniolam1000752 b266fbd
fix: resolved blockchainApplication reducer.test.js
eniolam1000752 5c78a64
fix: resolved blockchainApplication action.test.js
eniolam1000752 85360ed
fix: resolved getNetwork.test.js test
eniolam1000752 133fb96
fix: added unit test to useGetDefaultApplication
eniolam1000752 b66e55f
fix: resolved coverage issue on useApplicationManagement.test.js
eniolam1000752 ffca466
fix: resolved coverage on useTransactions
eniolam1000752 7e6c2c3
fix: resolved pr issues rasied by masoud
eniolam1000752 49db6ec
Merge branch 'feature/adapt-hw' into 4707-application-bootstrap
eniolam1000752 bb8e94d
fix: resolved merge conflicts
eniolam1000752 e01ac85
fix: removed default_network from webpack env
eniolam1000752 f6faee1
Merge branch 'feature/adapt-hw' into 4707-application-bootstrap
eniolam1000752 8c3b308
resolved merge conflict
eniolam1000752 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 35 additions & 31 deletions
66
src/modules/blockchainApplication/manage/hooks/useApplicationManagement.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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