-
Notifications
You must be signed in to change notification settings - Fork 9
Feature/campaign sync #576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * as indexerClient from "./internal/client.generated"; | ||
| export * as indexer from "./hooks"; | ||
| export * from "./types"; | ||
| export { syncApi } from "./sync"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { INDEXER_API_ENDPOINT_URL } from "@/common/_config"; | ||
|
|
||
| export const syncApi = { | ||
| /** | ||
| * Sync a campaign after creation or update | ||
| * @param campaignId - The on-chain campaign ID | ||
| */ | ||
| async campaign(campaignId: number | string): Promise<{ success: boolean; message?: string }> { | ||
| try { | ||
| const response = await fetch( | ||
| `${INDEXER_API_ENDPOINT_URL}/api/v1/campaigns/${campaignId}/sync`, | ||
| { method: "POST" }, | ||
| ); | ||
|
|
||
| if (!response.ok) { | ||
| const error = await response.json().catch(() => ({})); | ||
| console.warn("Failed to sync campaign:", error); | ||
| return { success: false, message: error?.error || "Sync failed" }; | ||
| } | ||
|
|
||
| const result = await response.json(); | ||
| console.log("Campaign synced:", result); | ||
| return { success: true, message: result.message }; | ||
| } catch (error) { | ||
| console.warn("Failed to sync campaign:", error); | ||
| return { success: false, message: String(error) }; | ||
| } | ||
| }, | ||
|
|
||
| /** | ||
| * Sync a campaign donation after a donation is made | ||
| * @param campaignId - The on-chain campaign ID | ||
| * @param txHash - Transaction hash from the donation | ||
| * @param senderId - Account ID of the donor | ||
| */ | ||
| async campaignDonation( | ||
| campaignId: number | string, | ||
| txHash: string, | ||
| senderId: string, | ||
| ): Promise<{ success: boolean; message?: string }> { | ||
| try { | ||
| const response = await fetch( | ||
| `${INDEXER_API_ENDPOINT_URL}/api/v1/campaigns/${campaignId}/donations/sync`, | ||
| { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ tx_hash: txHash, sender_id: senderId }), | ||
| }, | ||
| ); | ||
|
|
||
| if (!response.ok) { | ||
| const error = await response.json().catch(() => ({})); | ||
| console.warn("Failed to sync campaign donation:", error); | ||
| return { success: false, message: error?.error || "Sync failed" }; | ||
| } | ||
|
|
||
| const result = await response.json(); | ||
| return { success: true, message: result.message }; | ||
| } catch (error) { | ||
| console.warn("Failed to sync campaign donation:", error); | ||
| return { success: false, message: String(error) }; | ||
| } | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing null check on donation result.
providers.getTransactionLastResult(outcome)can returnundefinedif the transaction outcome doesn't have a successful result. This would causedonationto beundefined, which doesn't match theDonateResulttype wheredonationis required (non-nullableCampaignDonation).🛡️ Add validation
📝 Committable suggestion
🤖 Prompt for AI Agents