Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
25,005 changes: 13,565 additions & 11,440 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"type-check": "tsc --noEmit",
"type-check:watch": "tsc --noEmit --watch"
},
"eslintConfig": {
"extends": [
Expand All @@ -35,5 +37,10 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.9",
"typescript": "^5.9.2"
}
}
1 change: 0 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
Expand Down
8 changes: 0 additions & 8 deletions src/App.test.js

This file was deleted.

9 changes: 9 additions & 0 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';

test('renders buy an atom text', () => {
render(<App />);
const textElement = screen.getByText(/buy an atom/i);
expect(textElement).toBeInTheDocument();
});
3 changes: 2 additions & 1 deletion src/App.js → src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import { PayPalScriptProvider } from '@paypal/react-paypal-js';
import logo from './logo.svg';
import './App.css';
import Checkout from './Checkout';

function App() {
const App: React.FC = () => {
const CLIENT_ID = 'test';

return (
Expand Down
18 changes: 0 additions & 18 deletions src/Checkout.js

This file was deleted.

48 changes: 48 additions & 0 deletions src/Checkout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import { PayPalButtons } from '@paypal/react-paypal-js';

interface PayPalOrder {
payer: {
name: {
given_name: string;
surname?: string;
};
email_address?: string;
payer_id?: string;
};
purchase_units?: Array<any>;
status?: string;
}

interface OnApproveData {
orderID: string;
payerID?: string;
paymentID?: string;
billingToken?: string;
facilitatorAccessToken?: string;
}

interface OnApproveActions {
order: {
capture: () => Promise<PayPalOrder>;
get: () => Promise<PayPalOrder>;
};
redirect: (url: string) => void;
}

const Checkout: React.FC = () => {
return (
<div style={{ width: '75%', maxWidth: '500px' }}>
<PayPalButtons
onApprove={(data: OnApproveData, actions: OnApproveActions) => {
return actions.order.capture().then((details: PayPalOrder) => {
const name = details.payer.name.given_name;
alert(`Transaction completed by ${name}`);
});
}}
/>
</div>
);
}

export default Checkout;
16 changes: 10 additions & 6 deletions src/index.js → src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
const rootElement = document.getElementById('root');

if (rootElement) {
(ReactDOM as any).render(
<React.StrictMode>
<App />
</React.StrictMode>,
rootElement
);
}

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
Expand Down
13 changes: 13 additions & 0 deletions src/react-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// <reference types="react-scripts" />

declare module '*.svg' {
import * as React from 'react';
export const ReactComponent: React.FunctionComponent<React.SVGProps<SVGSVGElement> & { title?: string }>;
const src: string;
export default src;
}

declare module '*.css' {
const classes: { readonly [key: string]: string };
export default classes;
}
4 changes: 3 additions & 1 deletion src/reportWebVitals.js → src/reportWebVitals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const reportWebVitals = onPerfEntry => {
import { ReportHandler } from 'web-vitals';

const reportWebVitals = (onPerfEntry?: ReportHandler): void => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
Expand Down
File renamed without changes.
49 changes: 49 additions & 0 deletions src/types/paypal.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
declare module '@paypal/react-paypal-js' {
import { FC, ReactNode } from 'react';

export interface PayPalScriptOptions {
'client-id': string;
currency?: string;
intent?: string;
locale?: string;
'disable-funding'?: string;
'data-client-token'?: string;
components?: string;
[key: string]: any;
}

export interface PayPalScriptProviderProps {
options: PayPalScriptOptions;
children: ReactNode;
deferLoading?: boolean;
}

export const PayPalScriptProvider: FC<PayPalScriptProviderProps>;

export interface PayPalButtonsProps {
createOrder?: (data: any, actions: any) => Promise<string>;
onApprove?: (data: any, actions: any) => Promise<void> | void;
onCancel?: (data: any) => void;
onError?: (err: any) => void;
style?: {
layout?: 'vertical' | 'horizontal';
color?: 'gold' | 'blue' | 'silver' | 'white' | 'black';
shape?: 'rect' | 'pill';
height?: number;
label?: 'paypal' | 'checkout' | 'buynow' | 'pay' | 'installment';
tagline?: boolean;
};
disabled?: boolean;
forceReRender?: any[];
}

export const PayPalButtons: FC<PayPalButtonsProps>;

export const usePayPalScriptReducer: () => [any, any];
export const SCRIPT_LOADING_STATE: {
INITIAL: string;
PENDING: string;
REJECTED: string;
RESOLVED: string;
};
}
26 changes: 26 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "node20",
"moduleResolution": "nodenext",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}
Loading