-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff739b5
commit b219eb0
Showing
33 changed files
with
1,409 additions
and
332 deletions.
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
92 changes: 0 additions & 92 deletions
92
app/components/UI/InstallSnapApproval/InstallSnapApproval.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
99 changes: 99 additions & 0 deletions
99
app/components/UI/InstallSnapApprovalFlow/InstallSnapApprovalFlow.tsx
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,99 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import { | ||
InstallSnapApprovalArgs, | ||
SnapInstallState, | ||
} from './InstallSnapApprovalFlow.types'; | ||
import { InstallSnapConnectionRequest } from './components/InstallSnapConnectionRequest'; | ||
import { View } from 'react-native'; | ||
import { InstallSnapPermissionsRequest } from './components/InstallSnapPermissionsRequest'; | ||
import { InstallSnapSuccess } from './components/InstallSnapSuccess'; | ||
import { InstallSnapError } from './components/InstallSnapError'; | ||
import { SNAP_INSTALL_FLOW } from '../../../constants/test-ids'; | ||
import Logger from '../../../util/Logger'; | ||
|
||
const InstallSnapApprovalFlow = ({ | ||
requestData, | ||
onConfirm, | ||
onFinish, | ||
onCancel, | ||
}: InstallSnapApprovalArgs) => { | ||
const [installState, setInstallState] = useState<SnapInstallState>( | ||
SnapInstallState.Confirm, | ||
); | ||
|
||
const [installError, setInstallError] = useState<Error | undefined>( | ||
undefined, | ||
); | ||
|
||
const onConfirmNext = useCallback(() => { | ||
setInstallState(SnapInstallState.AcceptPermissions); | ||
}, []); | ||
|
||
const onPermissionsConfirm = useCallback(() => { | ||
try { | ||
onConfirm(); | ||
} catch (error) { | ||
Logger.error( | ||
error as Error, | ||
`${SNAP_INSTALL_FLOW} Failed to install snap`, | ||
); | ||
setInstallError(error as Error); | ||
setInstallState(SnapInstallState.SnapInstallError); | ||
} | ||
setInstallState(SnapInstallState.SnapInstalled); | ||
}, [onConfirm]); | ||
|
||
const onSnapInstalled = useCallback(() => { | ||
onFinish(); | ||
}, [onFinish]); | ||
|
||
const renderInstallStep = useCallback(() => { | ||
switch (installState) { | ||
case SnapInstallState.Confirm: | ||
return ( | ||
<InstallSnapConnectionRequest | ||
requestData={requestData.requestData} | ||
onConfirm={onConfirmNext} | ||
onCancel={onCancel} | ||
/> | ||
); | ||
case SnapInstallState.AcceptPermissions: | ||
return ( | ||
<InstallSnapPermissionsRequest | ||
requestData={requestData.requestData} | ||
onConfirm={onPermissionsConfirm} | ||
onCancel={onCancel} | ||
/> | ||
); | ||
case SnapInstallState.SnapInstalled: | ||
return ( | ||
<InstallSnapSuccess | ||
requestData={requestData.requestData} | ||
onConfirm={onSnapInstalled} | ||
onCancel={onCancel} | ||
/> | ||
); | ||
case SnapInstallState.SnapInstallError: | ||
return ( | ||
<InstallSnapError | ||
requestData={requestData.requestData} | ||
onConfirm={onSnapInstalled} | ||
onCancel={onCancel} | ||
error={installError} | ||
/> | ||
); | ||
} | ||
}, [ | ||
installError, | ||
installState, | ||
onCancel, | ||
onConfirmNext, | ||
onPermissionsConfirm, | ||
onSnapInstalled, | ||
requestData, | ||
]); | ||
|
||
return <View testID={SNAP_INSTALL_FLOW}>{renderInstallStep()}</View>; | ||
}; | ||
|
||
export default InstallSnapApprovalFlow; |
Oops, something went wrong.