aakash2310

Untitled

Apr 1st, 2023 (edited)
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. //import liraries
  2. import React, {Component, useEffect, useState} from 'react';
  3. import {View, Text, StyleSheet, Button,TouchableOpacity} from 'react-native';
  4. import Clipboard from '@react-native-clipboard/clipboard';
  5. import { showSuccess } from '../../utils/helperFunction';
  6. // import Clipboard from '@react-native-community/clipboard';
  7. // import Clipboard from '@react-native-clipboard/clipboard';
  8. // import Clipboard from 'react-native-advanced-clipboard';
  9. // create a component
  10. const Token = ({navigation}) => {
  11. const [copiedText, setCopiedText] = useState('');
  12.  
  13. const [loading, setloading] = useState(true);
  14. const [token, setToken] = useState('');
  15. useEffect(() => {
  16. const fetchData = async () => {
  17. try {
  18. const response = await fetch('https://smilechaincore.vercel.app/token');
  19. const json = await response.json();
  20. setToken(json.token.match(/.{1,4}/g).join(' '));
  21. setloading(false);
  22. } catch (error) {
  23. console.error(error);
  24. }
  25. };
  26. fetchData();
  27. }, []);
  28.  
  29. const copyToClipboard = () => {
  30. showSuccess("Copied !");
  31. Clipboard.setString(token);
  32. };
  33.  
  34. return loading ? (
  35. <View></View>
  36. ) : (
  37. <View
  38. style={{
  39. flex: 1,
  40. width: '70%',
  41. justifyContent: 'center',
  42. alignItems: 'center',
  43. }}>
  44. <Text>Your Encryption Key</Text>
  45. <Text
  46. style={{fontFamily: 'Courier New', fontWeight: 'bold', fontSize: 24}}>
  47. {token}
  48. </Text>
  49.  
  50. <Button title='📋 Copy To Clipboard' onPress={copyToClipboard}></Button>
  51.  
  52. <Button title='continue' onPress={()=> navigation.navigate('Signup', { token })}></Button>
  53. </View>
  54. );
  55. };
  56.  
  57. // define your styles
  58. const styles = StyleSheet.create({
  59. container: {
  60. flex: 1,
  61. justifyContent: 'center',
  62. alignItems: 'center',
  63. },
  64. });
  65.  
  66. //make this component available to the app
  67. export default Token;
  68.  
Advertisement
Add Comment
Please, Sign In to add comment