-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(connect-deeplink-example): new example react-native app for deep…
…links
- Loading branch information
Showing
11 changed files
with
229 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files | ||
|
||
# dependencies | ||
node_modules/ | ||
|
||
# Expo | ||
.expo/ | ||
dist/ | ||
web-build/ | ||
|
||
# Native | ||
*.orig.* | ||
*.jks | ||
*.p8 | ||
*.p12 | ||
*.key | ||
*.mobileprovision | ||
|
||
# Metro | ||
.metro-health-check* | ||
|
||
# debug | ||
npm-debug.* | ||
yarn-debug.* | ||
yarn-error.* | ||
|
||
# macOS | ||
.DS_Store | ||
*.pem | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# typescript | ||
*.tsbuildinfo |
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,90 @@ | ||
import { Button, StyleSheet, Text, View } from 'react-native'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { StatusBar } from 'expo-status-bar'; | ||
import * as Linking from 'expo-linking'; | ||
|
||
import TrezorConnect from '@trezor/connect-deeplink'; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: '#fff', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
dataContainer: { | ||
marginTop: 20, | ||
alignItems: 'flex-start', | ||
}, | ||
}); | ||
|
||
export const App = () => { | ||
const [errorData, setErrorData] = useState<any>(null); | ||
const [successData, setSuccessData] = useState<any>(null); | ||
|
||
const initialize = () => { | ||
TrezorConnect.init({ | ||
manifest: { | ||
email: '[email protected]', | ||
appUrl: 'http://your.application.com', | ||
}, | ||
deeplinkOpen: url => { | ||
// eslint-disable-next-line no-console | ||
console.log('deeplinkOpen', url); | ||
Linking.openURL(url); | ||
}, | ||
deeplinkCallbackUrl: Linking.createURL('/connect'), | ||
}); | ||
}; | ||
|
||
const getAddress = async () => { | ||
try { | ||
const response = await TrezorConnect.getAddress({ | ||
path: "m/49'/0'/0'/0/0", | ||
coin: 'btc', | ||
}); | ||
if (!response.success) { | ||
setSuccessData(null); | ||
setErrorData({ success: response.success }); | ||
|
||
return; | ||
} | ||
setErrorData(null); | ||
setSuccessData(response); | ||
} catch (error) { | ||
console.error('error', error); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
const subscription = Linking.addEventListener('url', event => { | ||
TrezorConnect.handleDeeplink(event.url); | ||
}); | ||
|
||
return () => subscription?.remove(); | ||
}, []); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Text>Trezor Connect Native example!</Text> | ||
<Button onPress={initialize} title="Initialize TrezorConnect" /> | ||
<Button onPress={getAddress} title="Get Address" /> | ||
{successData && ( | ||
<View style={styles.dataContainer}> | ||
<Text>Success: {successData.success ? 'Yes' : 'No'}</Text> | ||
<Text>Address: {successData.payload?.address}</Text> | ||
<Text>Path: {successData.payload?.path.join(', ')}</Text> | ||
<Text>Serialized Path: {successData.payload?.serializedPath}</Text> | ||
</View> | ||
)} | ||
|
||
{errorData && ( | ||
<View style={styles.dataContainer}> | ||
<Text>Success: {errorData.success ? 'Yes' : 'No'}</Text> | ||
</View> | ||
)} | ||
<StatusBar style="auto" /> | ||
</View> | ||
); | ||
}; |
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,11 @@ | ||
## Deep link example with Expo | ||
|
||
`@trezor/connect-deeplink` running with a React Native + Expo app | ||
|
||
### Run it | ||
|
||
`yarn android` | ||
|
||
Will start the Expo app in Android emulator/device. | ||
|
||
You will also need to have the Trezor Suite Lite app installed. Follow the instructions in [@suite-native/app](https://github.com/trezor/trezor-suite/blob/develop/suite-native/app/README.md) to run a dev version of the app. |
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,13 @@ | ||
{ | ||
"expo": { | ||
"name": "connect-deeplink-example", | ||
"slug": "connect-deeplink-example", | ||
"version": "1.0.0", | ||
"orientation": "portrait", | ||
"userInterfaceStyle": "light", | ||
"ios": { | ||
"supportsTablet": true | ||
}, | ||
"scheme": "connectdeeplinkexample" | ||
} | ||
} |
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,7 @@ | ||
module.exports = function (api) { | ||
api.cache(true); | ||
|
||
return { | ||
presets: ['babel-preset-expo'], | ||
}; | ||
}; |
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,8 @@ | ||
import { registerRootComponent } from 'expo'; | ||
|
||
import { App } from './App'; | ||
|
||
// registerRootComponent calls AppRegistry.registerComponent('main', () => App); | ||
// It also ensures that whether you load the app in Expo Go or in a native build, | ||
// the environment is set up appropriately | ||
registerRootComponent(App); |
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,25 @@ | ||
{ | ||
"name": "connect-deeplink-expo-example", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "expo start", | ||
"android": "expo start --android", | ||
"ios": "expo start --ios", | ||
"web": "expo start --web" | ||
}, | ||
"dependencies": { | ||
"@trezor/connect-deeplink": "workspace:*", | ||
"expo": "51.0.31", | ||
"expo-linking": "6.3.1", | ||
"expo-status-bar": "1.12.1", | ||
"react": "18.2.0", | ||
"react-native": "0.75.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.20.0", | ||
"@types/react": "18.2.45", | ||
"typescript": "^5.3.3" | ||
}, | ||
"private": true | ||
} |
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,7 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"compilerOptions": { "outDir": "./libDev" }, | ||
"references": [ | ||
{ "path": "../../connect-deeplink" } | ||
] | ||
} |
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