Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

fix: add buy sell retry mechanism #2505

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
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
32 changes: 22 additions & 10 deletions packages/app/hooks/creator-token/use-creator-token-buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { creatorTokenSwapRouterAbi } from "app/abi/CreatorTokenSwapRouterAbi";
import { getChannelByIdCacheKey } from "app/components/creator-channels/hooks/use-channel-detail";
import { getChannelMessageKey } from "app/components/creator-channels/hooks/use-channel-messages";
import { axios } from "app/lib/axios";
import { Logger } from "app/lib/logger";
import { useLogInPromise } from "app/lib/login-promise";
import { captureException } from "app/lib/sentry";
import { publicClient } from "app/lib/wallet-public-client";
import { formatAPIErrorMessage } from "app/utilities";
import { delay, formatAPIErrorMessage } from "app/utilities";

import { toast } from "design-system/toast";

Expand Down Expand Up @@ -191,15 +192,26 @@ export const useCreatorTokenBuy = (params: {
})
);

await axios({
url: "/v1/creator-token/poll-buy",
method: "POST",
data: {
creator_token_id: profileData.data.profile.creator_token.id,
quantity: tokenAmount,
tx_hash: transactionHash,
},
});
for (let i = 0; i < 3; i++) {
try {
await axios({
url: "/v1/creator-token/poll-buy",
method: "POST",
data: {
creator_token_id:
profileData.data.profile.creator_token.id,
quantity: tokenAmount,
tx_hash: transactionHash,
},
});
break;
} catch (e) {
Logger.error("tx not found");
}

await delay(2000);
}

mutate(
(key: any) => {
const channelId = profileData.data?.profile.channels[0]?.id;
Expand Down
31 changes: 21 additions & 10 deletions packages/app/hooks/creator-token/use-creator-token-sell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { axios } from "app/lib/axios";
import { Logger } from "app/lib/logger";
import { useLogInPromise } from "app/lib/login-promise";
import { publicClient } from "app/lib/wallet-public-client";
import { formatAPIErrorMessage } from "app/utilities";
import { delay, formatAPIErrorMessage } from "app/utilities";

import { toast } from "design-system/toast";

Expand Down Expand Up @@ -160,15 +160,26 @@ export const useCreatorTokenSell = () => {
contractAddress: arg.contractAddress,
})
);
await axios({
url: "/v1/creator-token/poll-sell",
method: "POST",
data: {
creator_token_id: arg.creatorTokenId,
token_ids: tokenIds,
tx_hash: txHash,
},
});

for (let i = 0; i < 3; i++) {
try {
await axios({
url: "/v1/creator-token/poll-sell",
method: "POST",
data: {
creator_token_id: arg.creatorTokenId,
token_ids: tokenIds,
tx_hash: txHash,
},
});
break;
} catch (e) {
Logger.error("tx not found");
}

await delay(2000);
}

return true;
}
}
Expand Down
Loading