From 834f844ff268b65b020557c4eadb47cc5867f295 Mon Sep 17 00:00:00 2001 From: ioan-ghisoi-cko Date: Mon, 2 Jun 2025 16:01:14 +0100 Subject: [PATCH] Update tsconfig to allow build and autoComplete --- src/Frames.tsx | 55 +++++++++++++++--------------- src/components/CardNumber.tsx | 2 +- src/components/Cvv.tsx | 4 +-- src/components/ExpiryDate.tsx | 4 +-- tsconfig.json | 63 ++++++++++++++++------------------- 5 files changed, 63 insertions(+), 65 deletions(-) diff --git a/src/Frames.tsx b/src/Frames.tsx index 65baedd..90690de 100644 --- a/src/Frames.tsx +++ b/src/Frames.tsx @@ -1,39 +1,40 @@ -import React, { useEffect } from "react"; -import { View, StyleSheet } from "react-native"; +import React, { useEffect, useReducer } from "react"; +import { View, StyleSheet, ImageSourcePropType } from "react-native"; import { framesReducer } from "./utils/reducer"; import { FramesContextType, FramesProps, FramesState, - FramesDispatch, + FrameCardTokenizationFailedEvent, } from "./types/types"; import { log } from "./utils/logger"; import { tokenize, formatDataForTokenization } from "./utils/http"; export const FramesContext = React.createContext({} as FramesContextType); +const initialState: FramesState = { + cardNumber: "", + cardBin: { + bin: "", + scheme: "", + }, + cardType: "", + cardIcon: null as unknown as ImageSourcePropType, + expiryDate: "", + cvv: "", + cvvLength: 3, + validation: { + cardNumber: false, + expiryDate: false, + cvv: false, + card: false, + }, +}; + const Frames = (props: FramesProps) => { - // @ts-ignore - const [state, dispatch]: [FramesState, FramesDispatch] = React.useReducer( + const [state, dispatch] = useReducer( framesReducer, - { - cardNumber: null, - cardBin: { - bin: null, - scheme: null, - }, - cardType: null, - cardIcon: undefined, - expiryDate: null, - cvv: null, - cvvLength: 3, - validation: { - cardNumber: false, - expiryDate: false, - cvv: false, - card: false, - }, - } + initialState ); const submitCard = async () => { @@ -43,7 +44,7 @@ const Frames = (props: FramesProps) => { "com.checkout.frames-mobile-sdk.token_requested", props.config ); - let response = await tokenize( + const response = await tokenize( formatDataForTokenization(state, props.config) ); if (props.config.debug) @@ -57,12 +58,14 @@ const Frames = (props: FramesProps) => { } catch (error) { if (props.config.debug) console.info(`Emitting "cardTokenizationFailed"`, error); - if (props.cardTokenizationFailed) props.cardTokenizationFailed(error); + if (props.cardTokenizationFailed && error instanceof Object) { + props.cardTokenizationFailed(error as FrameCardTokenizationFailedEvent); + } log( "error", "com.checkout.frames-mobile-sdk.exception", props.config, - error + error as object ); } }; diff --git a/src/components/CardNumber.tsx b/src/components/CardNumber.tsx index d61235c..aae5d90 100644 --- a/src/components/CardNumber.tsx +++ b/src/components/CardNumber.tsx @@ -16,7 +16,7 @@ const CardNumber: React.FC = (props) => { return ( = (props) => { +const Cvv: React.FC = (props) => { return ( {({ state, dispatch }) => { @@ -15,7 +15,7 @@ const Cvv: React.SFC = (props) => { } return ( = (props) => { +const ExpiryDate: React.FC = (props) => { return ( {({ state, dispatch }) => { @@ -15,7 +15,7 @@ const ExpiryDate: React.SFC = (props) => { } return (