Skip to content

Commit ef764b9

Browse files
SK-2050: add SkyflowRevealElementRef type
1 parent 999b188 commit ef764b9

6 files changed

Lines changed: 49 additions & 32 deletions

File tree

example/src/App.tsx

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,28 @@ const App = () => {
2626
return new Promise((resolve, reject) => {
2727
const Http = new XMLHttpRequest();
2828

29-
resolve('eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2MiOiJiOTYzZTcxMjFkZDY0YTZkOTY0MGQ3ZTNlNGNjODdhNyIsImF1ZCI6Imh0dHBzOi8vbWFuYWdlLWJsaXR6LnNreWZsb3dhcGlzLmRldiIsImV4cCI6MTc2NjMyNzg5NCwiaWF0IjoxNzY2MjQxNDk0LCJpc3MiOiJzYS1hdXRoQG1hbmFnZS1ibGl0ei5za3lmbG93YXBpcy5kZXYiLCJqdGkiOiJwZWViYTFiYmExZTA0ODFjODk0ZGM2MWVjN2ZhODk5OSIsInN1YiI6Im0xODQ2YzA2M2FlODQ4MjhhNzM4OWQ3ZTc0OTE5MzE5In0.c1n87PWuKU0LJ2-tSwlK5rsTUfjE_zKKAkeDYclkP0Xh_6gnAynA83UoxJV8qDbPsmu1zuCXW7Pt4-M6kCDUViVkv2KhHYDbDByXl_PG7cVNrj0d6kxkUm_FORRFmyyCWZKy3S2tomdw_gQar2LakuENuWXAR2gL5LSywb_XZmJxgolLe6RdqcHxdSQTV5j7PkjbhfSnkuMaFK0_z8fA8Wdm-44aCa-eALAFEHCZ0-YiQqlB_24ERQxL9bfD6dxiVJqyWVEg-hrGUE0WDUtNQVhoevbcQdC7GxH7AA_yk2xUxxJh7w7OzN1-YBmQWXGgQUZg4DXT9qnugNxeH8B6Tg')
29+
Http.onreadystatechange = () => {
30+
if (Http.readyState === 4) {
31+
if (Http.status === 200) {
32+
const response = JSON.parse(Http.responseText);
33+
resolve(response.accessToken);
34+
} else {
35+
reject('Error occured');
36+
}
37+
}
38+
};
39+
40+
Http.onerror = error => {
41+
reject('Error occured');
42+
};
43+
44+
const url = '<YOUR_AUTH_BEARER_TOKEN_API_URL>';
45+
Http.open('GET', url);
46+
Http.send();
3047
});
3148
},
32-
vaultID: 'tfe60a6eef66434b82e982285610e668',
33-
vaultURL: 'https://qhdmceurtnlz.vault.skyflowapis.dev',
49+
vaultID: '<VAULT_ID>',
50+
vaultURL: '<VAULT_URL>',
3451
options: {
3552
logLevel: LogLevel.ERROR,
3653
env: Env.PROD,
@@ -40,7 +57,7 @@ const App = () => {
4057
return (
4158
<SafeAreaView style={{ flex: 1 }}>
4259
<SkyflowProvider config={skyflowConfig}>
43-
{/* {!displayCollect && !displayComposable && !displayCobrandedCard && <>
60+
{!displayCollect && !displayComposable && !displayCobrandedCard && <>
4461
<View style={{ margin: 10 }}>
4562
<Button onPress={() => { setDisplayCollect(true) }} title='Collect And Reveal Elements' />
4663
</View>
@@ -50,14 +67,14 @@ const App = () => {
5067
<View style={{ margin: 10 }}>
5168
<Button onPress={() => { setDisplayCobrandedCard(true) }} title='Co-branded Card' />
5269
</View>
53-
</>} */}
70+
</>}
5471

55-
{true && <ElementView handleReset={handleReset} />}
56-
{/* {displayComposable && <ComposableElements handleReset={handleReset} />}
57-
{displayCobrandedCard && <CardBrandChoice handleReset={handleReset} />} */}
72+
{displayCollect && <ElementView handleReset={handleReset} />}
73+
{displayComposable && <ComposableElements handleReset={handleReset} />}
74+
{displayCobrandedCard && <CardBrandChoice handleReset={handleReset} />}
5875
</SkyflowProvider>
5976
</SafeAreaView>
6077
);
6178
};
6279

63-
export default App;
80+
export default App;

example/src/ElementView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const ElementView = (props) => {
1919

2020
return (
2121
<View style={styles.container}>
22-
{true ? (
22+
{showReveal ? (
2323
<RevealElements tokens={tokens} setShowRevealView={setShowRevealView} handleReset={props.handleReset}/>
2424
) : (
2525
<CollectElements setTokens={setTokens} handleReset={props.handleReset}/>
@@ -35,4 +35,4 @@ const styles = StyleSheet.create({
3535
},
3636
});
3737

38-
export default ElementView;
38+
export default ElementView;

example/src/RevealElements.tsx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Copyright (c) 2022 Skyflow, Inc.
33
*/
44

5-
import React, { useRef } from 'react';
5+
import React from 'react';
66
import { Button, StyleSheet, View } from 'react-native';
77
import {
88
RedactionType,
@@ -15,8 +15,6 @@ const RevealElements = (props) => {
1515
const revealContainer = useRevealContainer();
1616
const skyflowContainer = useSkyflow();
1717

18-
const revealElementRef = useRef(null);
19-
2018
const handleReveal = () => {
2119
revealContainer
2220
.reveal()
@@ -28,16 +26,6 @@ const RevealElements = (props) => {
2826
});
2927
};
3028

31-
const handleSetToken = () => {
32-
if (revealElementRef.current) {
33-
console.log('Updating token via Ref...');
34-
// This calls the setToken method you defined in useImperativeHandle inside the SDK
35-
revealElementRef.current.setToken('57b28973-9690-4031-88fe-b98650d3ac93');
36-
} else {
37-
console.error('Ref is null, cannot set token');
38-
}
39-
};
40-
4129
const handleGet = () =>{
4230
const getRecord1 = {
4331
ids: [
@@ -86,8 +74,7 @@ const RevealElements = (props) => {
8674
return (
8775
<View>
8876
<RevealElement
89-
ref={revealElementRef}
90-
token={'INVALID_TOKEN'}
77+
token={props.tokens.card_number}
9178
container={revealContainer}
9279
label='Card Number'
9380
altText='XXXX XXXX XXXX XXXX'
@@ -96,7 +83,7 @@ const RevealElements = (props) => {
9683
errorTextStyles={revealerrorTextStyles}
9784
redaction={RedactionType.REDACTED}
9885
/>
99-
{/* <RevealElement
86+
<RevealElement
10087
token={props.tokens.expiration_date}
10188
container={revealContainer}
10289
label='Expiration Date'
@@ -124,12 +111,20 @@ const RevealElements = (props) => {
124111
inputStyles={revealInputStyles}
125112
labelStyles={revealLabelStyles}
126113
errorTextStyles={revealerrorTextStyles}
127-
/> */}
114+
/>
128115
<View style={buttonStyles.button}>
129116
<Button title='Reveal' onPress={handleReveal} />
130117
</View>
131118
<View style={buttonStyles.button}>
132-
<Button title='Update Token (Set Token)' color="#841584" onPress={handleSetToken} />
119+
<Button title='Get method' onPress={handleGet} />
120+
</View>
121+
<View style={buttonStyles.button}>
122+
<Button
123+
title='GO TO COLLECT'
124+
onPress={() => {
125+
props.setShowRevealView(null);
126+
}}
127+
/>
133128
</View>
134129
<View style={buttonStyles.button}>
135130
<Button
@@ -166,4 +161,4 @@ const buttonStyles = StyleSheet.create({
166161
margin: 10,
167162
},
168163
});
169-
export default RevealElements;
164+
export default RevealElements;

src/components/RevealElement/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import React, { useEffect, useImperativeHandle, forwardRef } from "react";
55
import { Text } from "react-native";
66
import RevealSkyflowElement from "../../core/RevealSkyflowElement";
7-
import { RevealElementProps } from "../../utils/constants"
7+
import { RevealElementProps, SkyflowRevealElementRef } from "../../utils/constants"
88
import SkyflowError from "../../utils/skyflow-error";
99
import SKYFLOW_ERROR_CODE from "../../utils/skyflow-error-code";
1010
import { formatInputFieldValue } from "../../utils/helpers";
1111
import { DEFAULT_INPUT_FIELD_TRANSLATION } from "../../core/constants";
1212

13-
const RevealElement = forwardRef((props: RevealElementProps, ref) => {
13+
const RevealElement = forwardRef<SkyflowRevealElementRef, RevealElementProps>((props, ref) => {
1414
const { container, label, format, translation, ...rest } = props;
1515

1616
const [element, setElement] = React.useState<RevealSkyflowElement | undefined>(undefined);

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export {
99
LogLevel,
1010
ValidationRuleType,
1111
RedactionType,
12+
SkyflowRevealElementRef,
1213
} from './utils/constants';
1314
export { CardType } from './core/constants'
1415
export { default as useCollectContainer } from './hooks/useCollectContainer';

src/utils/constants/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ export interface IRevealResponseType {
137137
errors?: Record<string, any>[];
138138
}
139139

140+
export interface SkyflowRevealElementRef {
141+
setToken: (newToken: string) => void;
142+
}
143+
140144
export enum ValidationRuleType {
141145
REGEX_MATCH_RULE = 'REGEX_MATCH_RULE',
142146
LENGTH_MATCH_RULE = 'LENGTH_MATCH_RULE',

0 commit comments

Comments
 (0)