Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/mob-3 Part 1 #29

Merged
merged 7 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ jobs:
- name: Install dependencies
run: cd payment_sdk && yarn install

- name: Run Lint Check
run: cd payment_sdk && yarn lint

- name: Run Jest tests
run: cd payment_sdk && yarn test
26 changes: 23 additions & 3 deletions example/PaymentScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {useState} from 'react';
import {
useColorScheme,
View,
Text,
TextInput,
Expand All @@ -18,6 +19,7 @@ export enum CurrencyTypes {
const PaymentScreen = () => {
const [amount, setAmount] = useState('');
const [currency, setCurrency] = useState(CurrencyTypes.JPY);
const colorScheme = useColorScheme(); // Detects the color scheme of the device

// use createPayment method to invoke the payment screen
const {createPayment} = KomojuSDK.useKomoju();
Expand Down Expand Up @@ -45,8 +47,21 @@ const PaymentScreen = () => {
setCurrency(key);
};

const dynamicStyles = StyleSheet.create({
container: {
backgroundColor: colorScheme === 'dark' ? '#333' : '#FFF',
},
text: {
color: colorScheme === 'dark' ? '#FFF' : '#000',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is pretty slick. Nice

},
input: {
backgroundColor: colorScheme === 'dark' ? '#555' : '#FFF',
color: colorScheme === 'dark' ? '#FFF' : '#000',
},
});

return (
<View style={styles.container}>
<View style={[styles.container, dynamicStyles.container]}>
<View style={styles.currencyRow}>
{(Object.keys(CurrencyTypes) as Array<keyof typeof CurrencyTypes>).map(
key => (
Expand All @@ -55,17 +70,21 @@ const PaymentScreen = () => {
style={[
styles.currencyText,
key === currency && styles.currencySelectedText,
dynamicStyles.text,
]}>
{key}
</Text>
</Pressable>
),
)}
</View>
<Text style={styles.title}>Enter Amount to Pay with Komoju</Text>
<Text style={[styles.title, dynamicStyles.text]}>
Enter Amount to Pay with Komoju
</Text>
<TextInput
style={styles.input}
style={[styles.input, dynamicStyles.input]}
placeholder="Enter amount"
placeholderTextColor={colorScheme === 'dark' ? '#CCC' : '#333'}
keyboardType="numeric"
value={amount}
onChangeText={setAmount}
Expand All @@ -75,6 +94,7 @@ const PaymentScreen = () => {
title="Checkout"
onPress={handleSessionPay}
disabled={!amount}
color={colorScheme === 'dark' ? '#888' : '#007AFF'}
/>
</View>
</View>
Expand Down
5 changes: 5 additions & 0 deletions payment_sdk/assets.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module '*.png';
declare module '*.jpg';
declare module '*.jpeg';
declare module '*.gif';
declare module '*.json';
16 changes: 16 additions & 0 deletions payment_sdk/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,20 @@ module.exports = {
"@babel/preset-typescript",
"module:@react-native/babel-preset",
],
plugins: [
[
'module-resolver',
{
root: ['./src'],
extensions: ['.ios.js', '.android.js', '.js', '.ts', '.tsx', '.json'],
alias: {
"@services": "./src/services",
"@assets": "./src/assets",
"@components": "./src/components",
"@util": "./src/util",
"@context": "./src/context"
}
}
]
]
};
91 changes: 86 additions & 5 deletions payment_sdk/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,93 @@
import globals from "globals";
import { fixupConfigRules } from "@eslint/compat";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginImport from "eslint-plugin-import";
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";
import { fixupConfigRules } from "@eslint/compat";
import globals from "globals";
import tseslint from "typescript-eslint";

export default [
{ languageOptions: { globals: globals.browser } },
{
ignores: [
"node_modules/",
"dist/*",
"*.config.js",
"*.config.mjs",
"babel.config.js",
"setupTests.js",
"src/__tests__/*",
]
},
{
files: ["**/*.ts", "**/*.tsx"],
languageOptions:
{ globals: globals.browser }
},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
...fixupConfigRules(pluginReactConfig),
];
{
plugins: {
import: pluginImport,
},
rules: {
"import/order": [
"error",
{
groups: [
["builtin", "external", "internal"],
["parent", "sibling", "index"],
[]
],
pathGroups: [
{
pattern: "react",
group: "external",
position: "before"
},
{
pattern: "react-native",
group: "external",
position: "before"
},
{
pattern: "react-native-*",
group: "external",
position: "before"
},
{
pattern: "@context/**",
group: "internal",
position: "after"
},
{
pattern: "@components/**",
group: "internal",
position: "after"
},
{
pattern: "@services/**",
group: "internal",
position: "after"
},
{
pattern: "@util/**",
group: "internal",
position: "after"
},
{
pattern: "@assets/**",
group: "internal",
position: "after"
}
],
pathGroupsExcludedImportTypes: ["react", "react-native"],
"newlines-between": "always",
alphabetize: {
order: "asc",
caseInsensitive: true
}
}
]
}
}
];
9 changes: 8 additions & 1 deletion payment_sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const { pathsToModuleNameMapper } = require("ts-jest");

const { compilerOptions } = require("./tsconfig.json");

module.exports = {
preset: "react-native",
testEnvironment: "node",
modulePathIgnorePatterns: ["<rootDir>/node_modules"],
setupFiles: ["<rootDir>/setupTests.js"],
setupFilesAfterEnv: ["@testing-library/jest-native/extend-expect"],
transformIgnorePatterns: [],
};
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: "<rootDir>/src/" }),
};
19 changes: 13 additions & 6 deletions payment_sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
"name": "react-native-komoju",
"version": "1.0.0",
"description": "degica payment SDK",
"main": "src/index.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": ["dist"],
"scripts": {
"build": "npm run build:js && npm run build:types",
"build:js": "babel src --out-dir dist --extensions \".ts,.tsx\" --copy-files",
"build:types": "tsc --emitDeclarationOnly --outDir dist",
"test": "jest",
"lint": "eslint . --ignore-pattern babel.config.js --ignore-pattern jest.config.js --ignore-pattern setupTests.js"
"lint": "eslint ."
},
"author": "",
"license": "MIT",
Expand All @@ -23,7 +28,9 @@
"@types/react": "^18.3.3",
"@typescript-eslint/parser": "^7.12.0",
"babel-jest": "^29.7.0",
"babel-plugin-module-resolver": "^5.0.2",
"eslint": "9.x",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-react": "^7.34.2",
"globals": "^15.3.0",
"jest": "^29.7.0",
Expand All @@ -42,10 +49,10 @@
"i18next": "^23.11.5",
"react-i18next": "^14.1.2",
"react-native-svg": "^15.3.0",
"react-native-webview": "^13.10.2",
"react-native-worklets-core": "^1.3.3",
"react-native-vision-camera": "^4.3.2",
"react-native-vision-camera-text-recognition": "^3.0.4"
"react-native-vision-camera-text-recognition": "^3.0.4",
"react-native-webview": "^13.10.2",
"react-native-worklets-core": "^1.3.3"
},
"resolutions": {
"@types/react": "^18.2.44"
Expand All @@ -54,4 +61,4 @@
"react": "*",
"react-native": "*"
}
}
}
2 changes: 1 addition & 1 deletion payment_sdk/src/__tests__/CardInputGroup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { ReactNode } from "react";
import { render, fireEvent } from "@testing-library/react-native";

import { determineCardType, formatCreditCardNumber, formatExpiry } from "../util/helpers";
import { Actions, DispatchContext, StateContext } from "../state";
import { Actions, DispatchContext, StateContext } from "../context/state";
import CardInputGroup from "../components/CardInputGroup";
import { isCardNumberValid, validateCardExpiry } from "../util/validator";

Expand Down
2 changes: 1 addition & 1 deletion payment_sdk/src/__tests__/CardSection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fireEvent, render, waitFor } from "@testing-library/react-native";
import CardSection from "../components/sections/CardSection";

import StateProvider from "../components/paymentState/stateProvider";
import { DispatchContext, StateContext } from "../state";
import { DispatchContext, StateContext } from "../context/state";
import { PaymentType } from "../util/types";

export const mockState = {
Expand Down
1 change: 1 addition & 0 deletions payment_sdk/src/assets/languages/i18n.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';

import en from './en.json';
import ja from './ja.json';

Expand Down
42 changes: 23 additions & 19 deletions payment_sdk/src/components/CardInputGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import { StyleSheet, View } from "react-native";
import React, {
memo,
useContext,
useEffect,
useState,
useCallback,
} from "react";

import { StyleSheet, View } from "react-native";

import { SvgCssUri } from "react-native-svg/css";

import Input from "./Input";
import ScanCardButton from "./ScanCardButton";
import { Actions, DispatchContext, StateContext } from "../state";
import { isCardNumberValid, validateCardExpiry } from "../util/validator";
import {
determineCardType,
formatCreditCardNumber,
formatExpiry,
} from "../util/helpers";
import KomojuText from "./KomojuText";
import { Actions, DispatchContext, StateContext } from "@context/state";

import {
BASE_URL,
STATIC_CREDIT_CARD_CVC_SVG,
STATIC_CREDIT_CARD_SVG,
} from "../util/constants";
import { PaymentType, sessionShowPaymentMethodType } from "../util/types";
} from "@util/constants";
import {
determineCardType,
formatCreditCardNumber,
formatExpiry,
} from "@util/helpers";
import { PaymentType, sessionShowPaymentMethodType } from "@util/types";
import { isCardNumberValid, validateCardExpiry } from "@util/validator";

import CardScanner from "./CardScanner";
import Input from "./Input";
import KomojuText from "./KomojuText";
import ScanCardButton from "./ScanCardButton";

type Props = {
inputErrors: {
Expand All @@ -38,7 +42,7 @@ type Props = {
const CARD_WIDTH = 26;
const CARD_HEIGHT = 30;

const CardInputGroup = memo(({ inputErrors, resetError }: Props) => {
const CardInputGroup = ({ inputErrors, resetError }: Props) => {
const dispatch = useContext(DispatchContext);
const [cardType, setCardType] = useState<string | null>(null);
const [toggleScanCard, setToggleScanCard] = useState<boolean>(false);
Expand All @@ -51,7 +55,7 @@ const CardInputGroup = memo(({ inputErrors, resetError }: Props) => {
const type = determineCardType(cardNumber);
setCardType(type);
}
}, []);
}, [cardNumber]);

const renderSvg = (uri: string, widthMultiplier = 1) => (
<SvgCssUri
Expand Down Expand Up @@ -149,7 +153,7 @@ const CardInputGroup = memo(({ inputErrors, resetError }: Props) => {
<View style={styles.splitRow}>
<View style={styles.itemRow}>
<Input
value={cardExpiredDate}
value={cardExpiredDate as string}
keyboardType="number-pad"
testID="cardExpiryInput"
placeholder="MM / YY"
Expand All @@ -168,7 +172,7 @@ const CardInputGroup = memo(({ inputErrors, resetError }: Props) => {
</View>
<View style={styles.itemRow}>
<Input
value={cardCVV}
value={cardCVV as string}
testID="cardCVVInput"
keyboardType="number-pad"
placeholder="CVV"
Expand All @@ -190,9 +194,9 @@ const CardInputGroup = memo(({ inputErrors, resetError }: Props) => {
)}
</View>
);
});
};

export default CardInputGroup;
export default memo(CardInputGroup);

const styles = StyleSheet.create({
parentContainer: {
Expand Down
Loading
Loading