Skip to content

Commit

Permalink
Add setters for fetch ephemeral key function (#59)
Browse files Browse the repository at this point in the history
* feat: add new function

* fix: set type

* fix: lint

* style: ordering
  • Loading branch information
torrance-stripe authored Dec 8, 2023
1 parent efce81b commit 8ee2caf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@babel/preset-flow": "7.18.6",
"@babel/preset-react": "7.18.6",
"@rollup/plugin-replace": "^2.3.1",
"@stripe/connect-js": "3.1.0-beta.1",
"@stripe/connect-js": "3.2.2-beta-1",
"@types/jest": "^24.0.25",
"@types/react": "^16.8.0",
"@types/react-dom": "^16.8.0",
Expand Down Expand Up @@ -83,7 +83,7 @@
"zx": "^4.2.0"
},
"peerDependencies": {
"@stripe/connect-js": ">=3.1.0-beta.1",
"@stripe/connect-js": ">=3.2.2-beta-1",
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
}
Expand Down
6 changes: 6 additions & 0 deletions src/Components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {useCreateComponent} from './useCreateComponent';
import {useAttachAttribute} from './utils/useAttachAttribute';
import {useUpdateWithSetter} from './utils/useUpdateWithSetter';
import {FetchEphemeralKeyFunction} from './types';

export const ConnectPayments = (): JSX.Element => {
const {wrapper} = useCreateComponent('payments');
Expand Down Expand Up @@ -95,10 +96,12 @@ export const ConnectIssuingCard = ({
defaultCard,
cardArtFileLink,
cardSwitching,
fetchEphemeralKey,
}: {
defaultCard?: string;
cardArtFileLink?: string;
cardSwitching?: boolean;
fetchEphemeralKey?: FetchEphemeralKeyFunction;
}): JSX.Element => {
const {wrapper, component: issuingCard} = useCreateComponent('issuing-card');

Expand All @@ -111,6 +114,9 @@ export const ConnectIssuingCard = ({
useUpdateWithSetter(issuingCard, cardSwitching, (comp, val) =>
comp.setCardSwitching(val)
);
useUpdateWithSetter(issuingCard, fetchEphemeralKey, (comp, val) =>
comp.setFetchEphemeralKey(val)
);

return wrapper;
};
Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type FetchEphemeralKeyFunction = (fetchParams: {
issuingCard: string;
nonce: string;
}) => Promise<{
issuingCard: string;
nonce: string;
ephemeralKeySecret: string;
}>;
8 changes: 7 additions & 1 deletion src/utils/useUpdateWithSetter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from 'react';
import {FetchEphemeralKeyFunction} from '../types';

export const useUpdateWithSetter = <
T extends HTMLElement,
V extends string | boolean | (() => void) | undefined
V extends
| string
| boolean
| (() => void)
| FetchEphemeralKeyFunction
| undefined
>(
component: T | null,
value: V,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1430,10 +1430,10 @@
dependencies:
"@sinonjs/commons" "^3.0.0"

"@stripe/connect-js@3.1.0-beta.1":
version "3.1.0-beta.1"
resolved "https://registry.yarnpkg.com/@stripe/connect-js/-/connect-js-3.1.0-beta.1.tgz#1a25bad08d0939e2083615996eecdd18da35fc60"
integrity sha512-zJnJdG1O/PTv0k70a2o53WRtNxbW2/mh+/uOGm7zY6Oy5AJ1+521Ud1cgNZsxn///uUDSkHyVHGnH/tENpV75g==
"@stripe/connect-js@3.2.2-beta-1":
version "3.2.2-beta-1"
resolved "https://registry.yarnpkg.com/@stripe/connect-js/-/connect-js-3.2.2-beta-1.tgz#40b1998910071d0787b03846bfe7016df0f4ff98"
integrity sha512-yWhBszahubsEahHJcz6k5d2A+7ta11cIcEzCwCcX7qKvPswCSWZX1HVJ4vT+oHWBFuS3gYqkSGJdQe57DTBTkg==
dependencies:
"@rollup/plugin-json" "^6.0.0"

Expand Down

0 comments on commit 8ee2caf

Please sign in to comment.