-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): WIP native connect popup
- Loading branch information
Showing
12 changed files
with
147 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "@suite-native/module-connect-popup", | ||
"version": "1.0.0", | ||
"private": true, | ||
"license": "See LICENSE.md in repo root", | ||
"sideEffects": false, | ||
"main": "src/index", | ||
"scripts": { | ||
"depcheck": "yarn g:depcheck", | ||
"lint:js": "yarn g:eslint '**/*.{ts,tsx,js}'", | ||
"type-check": "yarn g:tsc --build" | ||
}, | ||
"dependencies": { | ||
"@suite-native/atoms": "workspace:*", | ||
"@suite-native/navigation": "workspace:*", | ||
"expo-linking": "^6.3.1" | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
suite-native/module-connect-popup/src/hooks/useConnectPopup.ts
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,47 @@ | ||
import { | ||
StackToStackCompositeNavigationProps, | ||
RootStackParamList, | ||
RootStackRoutes, | ||
} from '@suite-native/navigation'; | ||
import { useNavigation } from '@react-navigation/native'; | ||
import * as Linking from 'expo-linking'; | ||
import { useEffect } from 'react'; | ||
|
||
type NavigationProp = StackToStackCompositeNavigationProps< | ||
RootStackParamList, | ||
RootStackRoutes.ConnectPopup, | ||
RootStackParamList | ||
>; | ||
|
||
// TODO: wull be necessary to handle if device is not connected/unlocked so we probably want to wait until user unlock device | ||
// we already have some modals like biometrics or coin enabled which are waiting for device to be connected | ||
export const useConnectPopup = () => { | ||
const navigation = useNavigation<NavigationProp>(); | ||
|
||
const navigateToConnectPopup = (url: string) => { | ||
const parsedUrl = Linking.parse(url); | ||
navigation.navigate(RootStackRoutes.ConnectPopup, { parsedUrl }); | ||
}; | ||
|
||
useEffect(() => { | ||
const navigateToInitalUrl = async () => { | ||
const currentUrl = await Linking.getInitialURL(); | ||
console.log('currentUrl', currentUrl); | ||
if (currentUrl) { | ||
navigateToConnectPopup(currentUrl); | ||
} | ||
}; | ||
navigateToInitalUrl(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
// there could be when you open same deep link for second time and in that case it will be ignored | ||
// this could be probably handed by Linking.addEventListener | ||
const subscription = Linking.addEventListener('url', event => { | ||
console.log('url event received', event.url); | ||
navigateToConnectPopup(event.url); | ||
}); | ||
|
||
return () => subscription?.remove(); | ||
}, []); | ||
}; |
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,2 @@ | ||
export * from './screens/ConnectPopupScreen'; | ||
export * from './hooks/useConnectPopup'; |
37 changes: 37 additions & 0 deletions
37
suite-native/module-connect-popup/src/screens/ConnectPopupScreen.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,37 @@ | ||
import { Box, Button, Text } from '@suite-native/atoms'; | ||
import { | ||
RootStackParamList, | ||
RootStackRoutes, | ||
Screen, | ||
ScreenSubHeader, | ||
StackProps, | ||
} from '@suite-native/navigation'; | ||
import * as Linking from 'expo-linking'; | ||
|
||
export const ConnectPopupScreen = ({ | ||
route, | ||
}: StackProps<RootStackParamList, RootStackRoutes.TransactionDetail>) => { | ||
return ( | ||
<Screen | ||
screenHeader={ | ||
<ScreenSubHeader | ||
closeActionType="close" | ||
content={<Text>Connect Popup Native</Text>} | ||
/> | ||
} | ||
> | ||
<Box alignItems="center" justifyContent="center" flex={1}> | ||
<Text>{JSON.stringify(route.params)}</Text> | ||
<Button | ||
onPress={() => { | ||
Linking.openURL( | ||
`trezorsuitelite://send?coin=btc&address=1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2&amount=${Math.random()}`, | ||
); | ||
}} | ||
> | ||
Open URL in this app | ||
</Button> | ||
</Box> | ||
</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,5 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { "outDir": "libDev" }, | ||
"references": [] | ||
} |
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