-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(suite-native): use correct receive flow screens for connected device
- Loading branch information
Showing
22 changed files
with
286 additions
and
121 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "@suite-native/module-receive", | ||
"version": "1.0.0", | ||
"private": true, | ||
"license": "See LICENSE.md in repo root", | ||
"sideEffects": false, | ||
"main": "src/index", | ||
"scripts": { | ||
"depcheck": "yarn g:depcheck", | ||
"type-check": "yarn g:tsc --build" | ||
}, | ||
"dependencies": { | ||
"@react-navigation/native": "6.1.18", | ||
"@react-navigation/native-stack": "6.11.0", | ||
"@suite-native/accounts": "workspace:*", | ||
"@suite-native/device-manager": "workspace:*", | ||
"@suite-native/navigation": "workspace:*", | ||
"react": "18.2.0", | ||
"react-native": "0.76.1", | ||
"react-redux": "8.0.7" | ||
} | ||
} |
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 @@ | ||
export * from './navigation/ReceiveStackNavigator'; |
23 changes: 23 additions & 0 deletions
23
suite-native/module-receive/src/navigation/ReceiveStackNavigator.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,23 @@ | ||
import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
|
||
import { | ||
ReceiveStackParamList, | ||
ReceiveStackRoutes, | ||
stackNavigationOptionsConfig, | ||
} from '@suite-native/navigation'; | ||
|
||
import { ReceiveAccountsScreen } from '../screens/ReceiveAccountsScreen'; | ||
|
||
const ReceiveStack = createNativeStackNavigator<ReceiveStackParamList>(); | ||
|
||
export const ReceiveStackNavigator = () => ( | ||
<ReceiveStack.Navigator | ||
initialRouteName={ReceiveStackRoutes.ReceiveAccounts} | ||
screenOptions={stackNavigationOptionsConfig} | ||
> | ||
<ReceiveStack.Screen | ||
name={ReceiveStackRoutes.ReceiveAccounts} | ||
component={ReceiveAccountsScreen} | ||
/> | ||
</ReceiveStack.Navigator> | ||
); |
50 changes: 50 additions & 0 deletions
50
suite-native/module-receive/src/screens/ReceiveAccountsScreen.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,50 @@ | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { useNavigation } from '@react-navigation/native'; | ||
|
||
import { selectIsPortfolioTrackerDevice } from '@suite-common/wallet-core'; | ||
import { AccountsList, AddAccountButton, OnSelectAccount } from '@suite-native/accounts'; | ||
import { useTranslate } from '@suite-native/intl'; | ||
import { | ||
ReceiveStackParamList, | ||
ReceiveStackRoutes, | ||
RootStackParamList, | ||
RootStackRoutes, | ||
Screen, | ||
ScreenSubHeader, | ||
StackToStackCompositeNavigationProps, | ||
} from '@suite-native/navigation'; | ||
|
||
type NavigationProps = StackToStackCompositeNavigationProps< | ||
ReceiveStackParamList, | ||
ReceiveStackRoutes.ReceiveAccounts, | ||
RootStackParamList | ||
>; | ||
|
||
export const ReceiveAccountsScreen = () => { | ||
const { translate } = useTranslate(); | ||
const navigation = useNavigation<NavigationProps>(); | ||
|
||
const isPortfolioTrackerDevice = useSelector(selectIsPortfolioTrackerDevice); | ||
|
||
const navigateToReceiveScreen: OnSelectAccount = ({ account, tokenAddress }) => | ||
navigation.navigate(RootStackRoutes.ReceiveModal, { | ||
accountKey: account.key, | ||
tokenContract: tokenAddress, | ||
closeActionType: 'back', | ||
}); | ||
|
||
return ( | ||
<Screen | ||
screenHeader={ | ||
<ScreenSubHeader | ||
content={translate('moduleReceive.receiveTitle')} | ||
rightIcon={!isPortfolioTrackerDevice && <AddAccountButton flowType="receive" />} | ||
closeActionType="close" | ||
/> | ||
} | ||
> | ||
<AccountsList onSelectAccount={navigateToReceiveScreen} hideTokensIntoModal /> | ||
</Screen> | ||
); | ||
}; |
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,9 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { "outDir": "libDev" }, | ||
"references": [ | ||
{ "path": "../accounts" }, | ||
{ "path": "../device-manager" }, | ||
{ "path": "../navigation" } | ||
] | ||
} |
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
81 changes: 81 additions & 0 deletions
81
suite-native/receive/src/components/ReceiveScreenHeader.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,81 @@ | ||
import { useEffect } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native'; | ||
|
||
import { AccountKey, TokenAddress } from '@suite-common/wallet-types'; | ||
import { | ||
AccountsRootState, | ||
selectAccountLabel, | ||
selectAccountNetworkSymbol, | ||
} from '@suite-common/wallet-core'; | ||
import { HStack, Text } from '@suite-native/atoms'; | ||
import { CryptoIcon } from '@suite-native/icons'; | ||
import { Translation } from '@suite-native/intl'; | ||
import { | ||
GoBackIcon, | ||
RootStackParamList, | ||
RootStackRoutes, | ||
ScreenSubHeader, | ||
} from '@suite-native/navigation'; | ||
import { selectAccountTokenSymbol, TokensRootState } from '@suite-native/tokens'; | ||
import TrezorConnect from '@trezor/connect'; | ||
|
||
type ReceiveScreenHeaderProps = { | ||
accountKey?: AccountKey; | ||
tokenContract?: TokenAddress; | ||
}; | ||
|
||
export const ReceiveScreenHeader = ({ accountKey, tokenContract }: ReceiveScreenHeaderProps) => { | ||
const { | ||
params: { closeActionType }, | ||
} = useRoute<RouteProp<RootStackParamList, RootStackRoutes.ReceiveModal>>(); | ||
const navigation = useNavigation(); | ||
const accountLabel = useSelector((state: AccountsRootState) => | ||
selectAccountLabel(state, accountKey), | ||
); | ||
const symbol = useSelector((state: AccountsRootState) => | ||
selectAccountNetworkSymbol(state, accountKey), | ||
); | ||
const tokenSymbol = useSelector((state: TokensRootState) => | ||
selectAccountTokenSymbol(state, accountKey, tokenContract), | ||
); | ||
|
||
useEffect(() => { | ||
const unsubscribe = navigation.addListener('beforeRemove', () => { | ||
// When leaving the screen, cancel the request for address on trezor device | ||
TrezorConnect.cancel(); | ||
}); | ||
|
||
return unsubscribe; | ||
}, [navigation]); | ||
|
||
return ( | ||
<ScreenSubHeader | ||
content={ | ||
<> | ||
<Text variant="highlight"> | ||
{symbol ? ( | ||
<Translation | ||
id="moduleReceive.screenTitle" | ||
values={{ coinSymbol: symbol.toUpperCase() }} | ||
/> | ||
) : ( | ||
<Translation id="moduleReceive.receiveTitle" /> | ||
)} | ||
</Text> | ||
<HStack spacing="sp8" alignItems="center"> | ||
{symbol && <CryptoIcon symbol={symbol} size="extraSmall" />} | ||
{accountLabel && ( | ||
<Text variant="highlight"> | ||
{accountLabel} | ||
{tokenSymbol && ` - ${tokenSymbol}`} | ||
</Text> | ||
)} | ||
</HStack> | ||
</> | ||
} | ||
leftIcon={<GoBackIcon closeActionType={closeActionType} />} | ||
/> | ||
); | ||
}; |
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,2 +1,3 @@ | ||
export * from './components/ReceiveAccount'; | ||
export * from './screens/ReceiveAccountScreen'; | ||
export * from './screens/ReceiveModalScreen'; | ||
export { ReceiveScreenHeader } from './components/ReceiveScreenHeader'; |
Oops, something went wrong.