Skip to content

Commit 8cc1e26

Browse files
authored
fix(keychain): align credits purchase with stripe graphql (#2483)
## Summary Update the generated keychain payment GraphQL types to match the latest internal Stripe schema. Keep credits purchases working by removing the deleted `purchaseType`, `starterpackId`, and `username` inputs from the credits Stripe and Layerswap requests. Move the purchase UI enum out of the generated API types so the credits purchase routes still compile after the schema change. ## Validation - `pnpm --filter @cartridge/keychain format:check` - `pnpm --filter @cartridge/keychain lint` - `pnpm --filter @cartridge/keychain build`
1 parent 380f2f7 commit 8cc1e26

File tree

10 files changed

+31
-45
lines changed

10 files changed

+31
-45
lines changed

packages/keychain/src/components/app.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ import { UpdateSessionRoute } from "./UpdateSessionRoute";
4444
import { Funding } from "./funding";
4545
import { Deposit } from "./funding/Deposit";
4646
import { useNavigation } from "@/context";
47-
import { Purchase } from "./purchase";
48-
import { PurchaseType } from "@/utils/api";
47+
import { Purchase, PurchaseType } from "./purchase";
4948
import { ChooseNetwork } from "./purchasenew/wallet/network";
5049
import { Claim } from "./purchasenew/claim/claim";
5150
import { Collections } from "./purchasenew/starterpack/collections";

packages/keychain/src/components/purchase/PurchaseContent.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { PurchaseType } from "@/utils/api";
21
import { AmountSelection } from "../funding/AmountSelection";
32
import { Balance, BalanceType } from "./Balance";
4-
import { PurchaseState } from "./types";
3+
import { PurchaseState, PurchaseType } from "./types";
54

65
export type PurchaseContentProps = {
76
state: PurchaseState;

packages/keychain/src/components/purchase/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ import { Elements } from "@stripe/react-stripe-js";
1313
import { type Appearance } from "@stripe/stripe-js";
1414
import { useMemo } from "react";
1515
import CheckoutForm from "./StripeCheckout";
16-
import { PurchaseType } from "@/utils/api";
1716
import { PaymentMethod } from "./PaymentMethod";
1817
import { PurchaseContent } from "./PurchaseContent";
1918
import { usePurchase } from "@/hooks/purchase";
20-
import { PurchaseState, PurchaseCreditsProps } from "./types";
19+
import { PurchaseState, PurchaseCreditsProps, PurchaseType } from "./types";
2120

22-
export { PurchaseState } from "./types";
21+
export { PurchaseState, PurchaseType } from "./types";
2322
export type {
2423
PurchaseCreditsProps,
2524
PricingDetails,

packages/keychain/src/components/purchase/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { StarterpackDetails } from "@/context";
22
import { ExternalWallet } from "@cartridge/controller";
3-
import { PurchaseType } from "@/utils/api";
3+
4+
export enum PurchaseType {
5+
Credits = "CREDITS",
6+
Starterpack = "STARTERPACK",
7+
}
48

59
export enum PurchaseState {
610
SELECTION = 0,

packages/keychain/src/components/slot/fund.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { useEffect, useState, useMemo } from "react";
22
import { useLocation } from "react-router-dom";
33
import { useTeamsQuery } from "@cartridge/ui/utils/api/cartridge";
4-
import { Purchase } from "../purchase";
5-
import { PurchaseType } from "@/utils/api";
4+
import { Purchase, PurchaseType } from "../purchase";
65
import {
76
Button,
87
Card,

packages/keychain/src/context/starterpack/credit-purchase.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export const CreditPurchaseProvider = ({
7474
try {
7575
const paymentIntent = await createPaymentIntent(
7676
usdToCredits(usdAmount),
77-
controller.username(),
7877
undefined,
7978
typeof starterpackId === "string" ? starterpackId : undefined,
8079
);

packages/keychain/src/hooks/payments/stripe.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { client } from "@/utils/graphql";
66
import {
77
CreateStripePaymentIntentDocument,
88
CreateStripePaymentIntentMutation,
9-
PurchaseType,
109
StripePaymentDocument,
1110
StripePaymentQuery,
1211
} from "@/utils/api";
@@ -50,12 +49,9 @@ const useStripePayment = ({ isSlot }: { isSlot?: boolean }) => {
5049
);
5150

5251
const createPaymentIntent = useCallback(
53-
async (
54-
wholeCredits: number,
55-
username: string,
56-
teamId?: string,
57-
starterpackId?: string,
58-
) => {
52+
async (wholeCredits: number, teamId?: string, _starterpackId?: string) => {
53+
void _starterpackId;
54+
5955
if (!controller) {
6056
throw new Error("Controller not connected");
6157
}
@@ -67,16 +63,11 @@ const useStripePayment = ({ isSlot }: { isSlot?: boolean }) => {
6763
CreateStripePaymentIntentDocument,
6864
{
6965
input: {
70-
username,
7166
credits: {
7267
amount: wholeCredits,
7368
decimals: 0,
7469
},
7570
teamId,
76-
starterpackId,
77-
purchaseType: starterpackId
78-
? PurchaseType.Starterpack
79-
: PurchaseType.Credits,
8071
isMainnet: isLiveMode,
8172
},
8273
},

packages/keychain/src/hooks/purchase.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export function usePurchase({
6262
try {
6363
const paymentIntent = await createPaymentIntent(
6464
wholeCredits,
65-
controller.username(),
6665
teamId,
6766
starterpackDetails?.id?.toString(),
6867
);

packages/keychain/src/utils/api/generated.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,11 +1389,9 @@ export type CreateCoinbaseOnrampOrderInput = {
13891389
};
13901390

13911391
export type CreateCryptoPaymentInput = {
1392-
credits?: InputMaybe<CreditsInput>;
1392+
credits: CreditsInput;
13931393
isMainnet?: InputMaybe<Scalars["Boolean"]>;
13941394
network: Network;
1395-
purchaseType: PurchaseType;
1396-
starterpackId?: InputMaybe<Scalars["ID"]>;
13971395
teamId?: InputMaybe<Scalars["ID"]>;
13981396
username: Scalars["String"];
13991397
};
@@ -1406,12 +1404,10 @@ export type CreateLayerswapDepositInput = {
14061404
};
14071405

14081406
export type CreateLayerswapPaymentInput = {
1409-
credits?: InputMaybe<CreditsInput>;
1407+
credits: CreditsInput;
14101408
destinationNetwork: LayerswapDestinationNetwork;
14111409
layerswapFees?: InputMaybe<Scalars["BigInt"]>;
1412-
purchaseType: PurchaseType;
14131410
sourceNetwork: LayerswapSourceNetwork;
1414-
starterpackId?: InputMaybe<Scalars["ID"]>;
14151411
teamId?: InputMaybe<Scalars["ID"]>;
14161412
};
14171413

@@ -1468,12 +1464,19 @@ export type CreateServiceInput = {
14681464
};
14691465

14701466
export type CreateStripePaymentIntentInput = {
1471-
credits?: InputMaybe<CreditsInput>;
1467+
credits: CreditsInput;
14721468
isMainnet?: InputMaybe<Scalars["Boolean"]>;
1473-
purchaseType: PurchaseType;
1474-
starterpackId?: InputMaybe<Scalars["ID"]>;
14751469
teamId?: InputMaybe<Scalars["ID"]>;
1476-
username: Scalars["String"];
1470+
};
1471+
1472+
export type CreateStripeStarterpackIntentInput = {
1473+
chainId: Scalars["String"];
1474+
isMainnet?: InputMaybe<Scalars["Boolean"]>;
1475+
quantity: Scalars["Int"];
1476+
referral?: InputMaybe<Scalars["String"]>;
1477+
referralGroup?: InputMaybe<Scalars["String"]>;
1478+
registryAddress: Scalars["String"];
1479+
starterpackId: Scalars["String"];
14771480
};
14781481

14791482
export type CredentialMetadata =
@@ -2976,6 +2979,7 @@ export type Mutation = {
29762979
createRpcCorsDomain: RpcCorsDomain;
29772980
createSession: Scalars["String"];
29782981
createStripePaymentIntent: StripePaymentIntent;
2982+
createStripeStarterpackIntent: StripePaymentIntent;
29792983
createTeam: Team;
29802984
decreaseBudget: Paymaster;
29812985
deleteDeployment: Scalars["Boolean"];
@@ -3129,6 +3133,10 @@ export type MutationCreateStripePaymentIntentArgs = {
31293133
input: CreateStripePaymentIntentInput;
31303134
};
31313135

3136+
export type MutationCreateStripeStarterpackIntentArgs = {
3137+
input: CreateStripeStarterpackIntentInput;
3138+
};
3139+
31323140
export type MutationCreateTeamArgs = {
31333141
data?: InputMaybe<TeamInput>;
31343142
name: Scalars["String"];
@@ -4416,12 +4424,6 @@ export type ProveVerifyResponse = {
44164424
verified?: Maybe<Scalars["Boolean"]>;
44174425
};
44184426

4419-
export enum PurchaseType {
4420-
Credits = "CREDITS",
4421-
/** @deprecated Starterpack purchases are now handled client-side */
4422-
Starterpack = "STARTERPACK",
4423-
}
4424-
44254427
export type Query = {
44264428
__typename?: "Query";
44274429
account?: Maybe<Account>;

packages/keychain/src/utils/payments.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
CreateLayerswapDepositInput,
44
CreateLayerswapPaymentInput,
55
LayerswapDestinationNetwork,
6-
PurchaseType,
76
} from "@/utils/api";
87
import { mapPlatformToLayerswapSourceNetwork } from "@/hooks/starterpack/layerswap";
98

@@ -37,15 +36,13 @@ export function depositToLayerswapInput(
3736
/**
3837
* Converts a credits purchase to a CreateLayerswapPaymentInput object.
3938
*
40-
* @param starterpackId An optional starterpack ID.
4139
* @param platform The source platform for the payment.
4240
* @param isMainnet Whether the transaction is for mainnet or testnet.
4341
* @param wholeCredits The amount of credits to purchase.
4442
* @param teamId An optional team ID.
4543
* @returns A CreateLayerswapPaymentInput object.
4644
*/
4745
export function creditsPurchaseToLayerswapInput(
48-
starterpackId: string | undefined,
4946
platform: ExternalPlatform,
5047
isMainnet: boolean,
5148
wholeCredits: number,
@@ -62,12 +59,10 @@ export function creditsPurchaseToLayerswapInput(
6259
return {
6360
sourceNetwork,
6461
destinationNetwork,
65-
purchaseType: PurchaseType.Credits,
6662
credits: {
6763
amount: wholeCredits,
6864
decimals: 0,
6965
},
70-
starterpackId,
7166
teamId,
7267
};
7368
}

0 commit comments

Comments
 (0)