Skip to content

Commit

Permalink
Ensures singular attachment for 3DS container
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissrogers committed Jan 30, 2024
1 parent d77cb71 commit 1dfd32a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
3 changes: 3 additions & 0 deletions lib/three-d-secure-action.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default class ThreeDSecureAction extends React.PureComponent {

const { actionTokenId } = props;

this._attached = false;
this._container = React.createRef();
this._risk = this.context.recurly.Risk();
this._threeDSecure = this._risk.ThreeDSecure({ actionTokenId });
Expand All @@ -82,7 +83,9 @@ export default class ThreeDSecureAction extends React.PureComponent {
}

componentDidMount () {
if (this._attached) return;
this._threeDSecure.attach(this._container.current);
this._attached = true;
}

render () {
Expand Down
12 changes: 1 addition & 11 deletions test/three-d-secure-action.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,9 @@ describe('<ThreeDSecureAction />', function () {
/>
));

getThreeDSecureInstanceFrom(fixture).emit('ready', );
getThreeDSecureInstanceFrom(fixture).emit('ready');
expect(subject).toHaveBeenCalled();
});

it('does nothing when no handler is provided', function () {
let fixture;

render(withRecurlyProvider(
<ThreeDSecureAction actionTokenId="test-action-token" ref={ref => fixture = ref} />
));

expect(() => getThreeDSecureInstanceFrom(fixture).emit('ready', example)).not.toThrow();
});
});

describe('[onToken]', function () {
Expand Down

0 comments on commit 1dfd32a

Please sign in to comment.