Skip to content

Commit

Permalink
Undo purchase stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinludu committed Oct 18, 2024
1 parent b9729b5 commit 0dc5d44
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 168 deletions.
5 changes: 0 additions & 5 deletions apps/scoutgame/app/(general)/notifications/loading.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import { useAccount, useSendTransaction, useSwitchChain } from 'wagmi';

import { IconButton } from 'components/common/Button/IconButton';
import { PointsIcon } from 'components/common/Icons';
import { usePurchase } from 'components/layout/PurchaseProvider';
import { useUser } from 'components/layout/UserProvider';
import { checkDecentTransactionAction } from 'lib/builderNFTs/checkDecentTransactionAction';
import { purchaseWithPointsAction } from 'lib/builderNFTs/purchaseWithPointsAction';
import { saveDecentTransactionAction } from 'lib/builderNFTs/saveDecentTransactionAction';
import type { MinimalUserInfo } from 'lib/users/interfaces';
Expand Down Expand Up @@ -79,7 +79,6 @@ export function NFTPurchaseFormContent({ builder }: NFTPurchaseProps) {
const initialQuantities = [1, 11, 111];
const pricePerNft = builder.price ? convertCostToPoints(builder.price).toLocaleString() : '';
const { address, chainId } = useAccount();
const { checkDecentTransaction, isExecutingTransaction } = usePurchase();

const { switchChainAsync } = useSwitchChain();

Expand Down Expand Up @@ -126,6 +125,20 @@ export function NFTPurchaseFormContent({ builder }: NFTPurchaseProps) {
}
});

const {
isExecuting: isExecutingTransaction,
hasSucceeded: transactionHasSucceeded,
executeAsync: checkDecentTransaction
} = useAction(checkDecentTransactionAction, {
onError({ error, input }) {
log.error('Error checking Decent transaction', { error, input });
setSubmitError(error.serverError?.message || 'Something went wrong');
},
onExecute() {
setSubmitError(null);
}
});

const {
isExecuting: isSavingDecentTransaction,
hasSucceeded: savedDecentTransaction,
Expand Down Expand Up @@ -312,7 +325,7 @@ export function NFTPurchaseFormContent({ builder }: NFTPurchaseProps) {
typeof allowance === 'bigint' &&
allowance < (typeof amountToPay === 'bigint' ? amountToPay : BigInt(0));

if (hasPurchasedWithPoints || savedDecentTransaction) {
if (hasPurchasedWithPoints || (savedDecentTransaction && transactionHasSucceeded)) {
return <SuccessView builder={builder} />;
}

Expand Down
8 changes: 1 addition & 7 deletions apps/scoutgame/components/layout/AppProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { WagmiProvider } from 'components/common/WalletLogin/WagmiProvider';
import type { SessionUser } from 'lib/session/getUserFromSession';
import theme from 'theme/theme';

import { PurchaseProvider } from './PurchaseProvider';
import { SnackbarProvider } from './SnackbarContext';
import { SWRProvider } from './SwrProvider';
import { UserProvider } from './UserProvider';

Expand All @@ -21,11 +19,7 @@ export function AppProviders({ children, user }: { children: ReactNode; user: Se
<CssBaseline enableColorScheme />
<WagmiProvider>
<SWRProvider>
<UserProvider userSession={user}>
<SnackbarProvider>
<PurchaseProvider>{children}</PurchaseProvider>
</SnackbarProvider>
</UserProvider>
<UserProvider userSession={user}>{children}</UserProvider>
</SWRProvider>
</WagmiProvider>
</ThemeProvider>
Expand Down
74 changes: 0 additions & 74 deletions apps/scoutgame/components/layout/PurchaseProvider.tsx

This file was deleted.

63 changes: 0 additions & 63 deletions apps/scoutgame/components/layout/SnackbarContext.tsx

This file was deleted.

16 changes: 0 additions & 16 deletions packages/scoutgame/src/builderNfts/handlePendingTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ export async function handlePendingTransaction({
throw new InvalidInputError(`Pending transaction id must be a valid uuid`);
}

const initialTransaction = await prisma.pendingNftTransaction.findFirst({
where: {
id: pendingTransactionId
}
});

if (initialTransaction && (initialTransaction.status === 'completed' || initialTransaction.status === 'failed')) {
log.info(
'handlePendingTransaction has propably run twice since the transaction is already completed. Abording the process.',
{
pendingTransactionId
}
);
return;
}

// Atomically set the status to 'processing' only if it's currently 'pending'
const updatedTx = await prisma.pendingNftTransaction.updateMany({
where: {
Expand Down

0 comments on commit 0dc5d44

Please sign in to comment.