Skip to content
Open
Changes from all 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
23 changes: 15 additions & 8 deletions packages/cli/src/commands/mpp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
ISpendRequestResource,
} from '@stripe/link-sdk';
import { Cli, z } from 'incur';
import React from 'react';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Dumb q; do we understand this change? Was this unused before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes! it was not used before (similar to runMppPayFullFlow) --- it isn't necessary for this fix though, I can restore them to keep the PR focused 🫡

import type { CliAuthStorage } from '../../auth/storage';
import { renderInteractive } from '../../utils/render-interactive';
import { requireAuth } from '../../utils/require-auth';
Expand All @@ -16,12 +15,24 @@ import {
type PayResult,
probeMppRequest,
readPayResult,
runMppPayFullFlow,
runMppPayWithSpendRequest,
} from './pay';
import { createMppRequest } from './request';
import { decodeOptions, payOptions } from './schema';

export function resolveInteractivePayResult(
result: PayResult | null | undefined,
): PayResult | undefined {
if (result === undefined) {
throw new Error('Component exited without producing a result');
}
if (result === null) {
process.exitCode = 1;
return undefined;
}
return result;
}

export function createMppCli(
repository: ISpendRequestResource,
paymentMethodsFactory: () => IPaymentMethodsResource,
Expand Down Expand Up @@ -50,7 +61,7 @@ export function createMppCli(
const headers = opts.header?.length ? opts.header : undefined;

if (!c.agent && !c.formatExplicit) {
let capturedResult: PayResult | null = null;
let capturedResult: PayResult | null | undefined;
return renderInteractive(
<MppPay
url={url}
Expand All @@ -68,11 +79,7 @@ export function createMppCli(
capturedResult = result;
}}
/>,
() => {
if (!capturedResult)
throw new Error('Component exited without producing a result');
return capturedResult;
},
() => resolveInteractivePayResult(capturedResult),
);
}

Expand Down
Loading