Skip to content

Commit

Permalink
Added validation stage when creating the wave item
Browse files Browse the repository at this point in the history
  • Loading branch information
dkildar committed Nov 18, 2024
1 parent b6b48d0 commit cb22754
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
23 changes: 22 additions & 1 deletion src/api/hive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
WithdrawRoute,
Witness
} from "@/entities";
import { isCommunity, parseAsset, vestsToRshares } from "@/utils";
import { delay, isCommunity, parseAsset, vestsToRshares } from "@/utils";
import { OrdersDataItem } from "@/entities/hive/orders-data-item";

export const client = new Client(SERVERS, {
Expand Down Expand Up @@ -383,3 +383,24 @@ export const getRcOperationStats = (): Promise<any> => client.call("rc_api", "ge

export const getContentReplies = (author: string, permlink: string): Promise<Entry[] | null> =>
client.call("condenser_api", "get_content_replies", { author, permlink });

/**
* Helps to validate if post was really created on Blockchain
*/
export async function validatePostCreating(author: string, permlink: string, attempts = 0) {
if (attempts === 3) {
return;
}

let response: Entry | undefined;
try {
response = await getPost(author, permlink);
} catch (e) {
response = undefined;
}
if (!response) {
await delay(3000);
attempts += 1;
return validatePostCreating(author, permlink, attempts);
}
}
24 changes: 1 addition & 23 deletions src/app/submit/_api/publish.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import * as bridgeApi from "../../../api/bridge";
import { getPost } from "../../../api/bridge";
import { markAsPublished, updateSpeakVideoInfo } from "@/api/threespeak";
import { comment, formatError, reblog } from "@/api/operations";
import { useThreeSpeakManager } from "../_hooks";
Expand All @@ -13,7 +12,6 @@ import { useGlobalStore } from "@/core/global-store";
import { BeneficiaryRoute, Entry, FullAccount, RewardType } from "@/entities";
import {
createPermlink,
delay,
isCommunity,
makeApp,
makeCommentOptions,
Expand All @@ -27,27 +25,7 @@ import { useRouter } from "next/navigation";
import { QueryIdentifiers } from "@/core/react-query";
import { EcencyEntriesCacheManagement } from "@/core/caches";
import { postBodySummary } from "@ecency/render-helper";

/**
* Helps to validate if post was really created on Blockchain
*/
async function validatePostCreating(author: string, permlink: string, attempts = 0) {
if (attempts === 3) {
return;
}

let response: Entry | undefined;
try {
response = await getPost(author, permlink);
} catch (e) {
response = undefined;
}
if (!response) {
await delay(3000);
attempts += 1;
return validatePostCreating(author, permlink, attempts);
}
}
import { validatePostCreating } from "@/api/hive";

export function usePublishApi(onClear: () => void) {
const queryClient = useQueryClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EntryMetadataManagement } from "@/features/entry-management";
import { comment } from "@/api/operations";
import { EcencyEntriesCacheManagement } from "@/core/caches";
import { useMutation } from "@tanstack/react-query";
import { validatePostCreating } from "@/api/hive";

export function useThreadsApi() {
const activeUser = useGlobalStore((s) => s.activeUser);
Expand Down Expand Up @@ -44,6 +45,7 @@ export function useThreadsApi() {
.build();

await comment(author, parentAuthor, parentPermlink, permlink, "", raw, jsonMeta, null, true);
await validatePostCreating(activeUser?.username, permlink);

const nReply = tempEntry({
author: activeUser.data as FullAccount,
Expand Down

0 comments on commit cb22754

Please sign in to comment.