Skip to content
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
12 changes: 0 additions & 12 deletions apps/backoffice-tokenization/src/app/flow-roi/page.tsx

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions apps/backoffice-tokenization/src/app/flow-testing/create/page.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions apps/backoffice-tokenization/src/app/flow-testing/page.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Button } from "@tokenization/ui/button";
import { Input } from "@tokenization/ui/input";
import { Label } from "@tokenization/ui/label";
import { Loader2 } from "lucide-react";
import { useFundRoi } from "../hooks/useFundRoi";
import { useFundRoi } from "@/features/campaigns/hooks/useFundRoi";
import { toast } from "sonner";

interface FundRoiDialogProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { Button } from "@tokenization/ui/button";
import { Loader2, Power } from "lucide-react";
import { useToggleVault } from "../hooks/useToggleVault";
import { useToggleVault } from "@/features/campaigns/hooks/useToggleVault";
import { toast } from "sonner";

interface ToggleVaultButtonProps {
Expand All @@ -15,26 +15,27 @@ interface ToggleVaultButtonProps {
export function ToggleVaultButton({
vaultId,
currentlyEnabled,
campaignId,
onToggled,
}: ToggleVaultButtonProps) {
const nextState = !currentlyEnabled;

const { execute, isSubmitting, error } = useToggleVault({
onSuccess: (newEnabled) => {
toast.success(newEnabled ? "Vault enabled" : "Vault disabled");
onToggled(newEnabled);
onSuccess: () => {
toast.success(
currentlyEnabled ? "Vault disabled" : "Vault enabled",
);
onToggled(nextState);
},
});

const nextState = !currentlyEnabled;

return (
<>
<Button
size="sm"
variant={currentlyEnabled ? "destructive" : "outline"}
className="cursor-pointer h-8"
disabled={isSubmitting || currentlyEnabled === null}
onClick={() => execute(vaultId, nextState, campaignId)}
onClick={() => execute(vaultId, nextState)}
>
{isSubmitting ? (
<Loader2 className="h-3.5 w-3.5 animate-spin" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { ArrowUpCircle, Landmark } from "lucide-react";
import { useWalletContext } from "@tokenization/tw-blocks-shared/src/wallet-kit/WalletProvider";
import { CAMPAIGN_STATUS_CONFIG } from "@/features/campaigns/constants/campaign-status";
import { formatCurrency } from "@/lib/utils";
import { getVaultIsEnabled } from "@/features/flow-roi/services/roi.service";
import { ToggleVaultButton } from "@/features/flow-roi/components/ToggleVaultButton";
import { getVaultIsEnabled } from "@/features/campaigns/services/campaigns.api";
import { ToggleVaultButton } from "@/features/campaigns/components/roi/ToggleVaultButton";
import type { RoiTableRowProps } from "./types";

export function RoiTableRow({ campaign, balance, onAddFunds }: RoiTableRowProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { StatItem } from "@/components/shared/stat-item";
import { RoiTable } from "@/features/campaigns/components/roi/roi-table";
import { FundRoiDialog } from "@/features/flow-roi/components/FundRoiDialog";
import { FundRoiDialog } from "@/features/campaigns/components/roi/FundRoiDialog";
import { useRoi } from "@/features/campaigns/hooks/use-roi";
import { useCampaigns } from "@/features/campaigns/hooks/use-campaigns";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { useState } from "react";
import { useWalletContext } from "@tokenization/tw-blocks-shared/src/wallet-kit/WalletProvider";
import { signTransaction } from "@tokenization/tw-blocks-shared/src/wallet-kit/wallet-kit";
import { submitAndExtractAddress } from "@/features/flow-testing/services/soroban.service";
import { buildUsdcTransferXdr } from "../services/transfer.service";
import { submitAndExtractAddress } from "@/features/campaigns/services/soroban.service";
import { buildUsdcTransferXdr } from "@/features/campaigns/services/transfer.service";

interface UseFundRoiParams {
onSuccess?: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
import { useState } from "react";
import { useWalletContext } from "@tokenization/tw-blocks-shared/src/wallet-kit/WalletProvider";
import { signTransaction } from "@tokenization/tw-blocks-shared/src/wallet-kit/wallet-kit";
import { submitAndExtractAddress } from "@/features/flow-testing/services/soroban.service";
import { enableVault } from "../services/roi.service";
import { updateCampaignStatus } from "@/features/campaigns/services/campaigns.api";
import { submitAndExtractAddress } from "@/features/campaigns/services/soroban.service";
import { enableVault } from "@/features/campaigns/services/campaigns.api";

interface UseToggleVaultParams {
onSuccess?: (newEnabled: boolean) => void;
onSuccess?: () => void;
}

export function useToggleVault({ onSuccess }: UseToggleVaultParams = {}) {
const { walletAddress } = useWalletContext();
const [isSubmitting, setIsSubmitting] = useState(false);
const [error, setError] = useState<string | null>(null);

const execute = async (vaultContractId: string, enabled: boolean, campaignId?: string) => {
const execute = async (vaultContractId: string, enabled: boolean) => {
if (!walletAddress) {
setError("Wallet not connected");
return;
Expand All @@ -40,11 +39,7 @@ export function useToggleVault({ onSuccess }: UseToggleVaultParams = {}) {

await submitAndExtractAddress(signedXdr);

if (enabled && campaignId) {
await updateCampaignStatus(campaignId, "CLAIMABLE").catch(() => null);
}

onSuccess?.(enabled);
onSuccess?.();
} catch (e) {
const message = e instanceof Error ? e.message : "Unexpected error";
setError(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,56 @@ export async function createCampaign(params: {
}): Promise<{ id: string }> {
return post("/campaigns", params);
}

async function get<T>(path: string): Promise<T> {
const res = await fetch(`${CORE_API}${path}`, {
headers: { "x-api-key": API_KEY },
});
if (!res.ok) {
const err = await res.json().catch(() => ({}));
throw new Error(
(err as { message?: string }).message ?? `Error ${res.status} on ${path}`,
);
}
return res.json() as Promise<T>;
}

async function patch<T>(path: string, body: unknown): Promise<T> {
const res = await fetch(`${CORE_API}${path}`, {
method: "PATCH",
headers: { "Content-Type": "application/json", "x-api-key": API_KEY },
body: JSON.stringify(body),
});
if (!res.ok) {
const err = await res.json().catch(() => ({}));
throw new Error(
(err as { message?: string }).message ?? `Error ${res.status} on ${path}`,
);
}
return res.json() as Promise<T>;
}

export async function enableVault(params: {
contractId: string;
admin: string;
enabled: boolean;
callerPublicKey: string;
}): Promise<{ unsignedXdr: string }> {
return post("/vault/availability-for-exchange", params);
}

export async function getVaultIsEnabled(
contractId: string,
callerPublicKey: string,
): Promise<{ enabled: boolean }> {
return get(
`/vault/is-enabled?contractId=${contractId}&callerPublicKey=${callerPublicKey}`,
);
}

export async function updateCampaignVaultId(
campaignId: string,
vaultId: string,
): Promise<unknown> {
return patch(`/campaigns/${campaignId}`, { vaultId });
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
TransactionBuilder,
Networks,
scValToNative,
Address,
} from "@stellar/stellar-sdk";

export interface DeployedContracts {
Expand Down Expand Up @@ -53,3 +54,46 @@ export async function submitAndExtractDeployedContracts(
const native = scValToNative(success.returnValue) as DeployedContracts;
return native;
}

export async function submitAndExtractAddress(
signedXdr: string,
): Promise<string | null> {
const server = new rpc.Server(
"https://soroban-testnet.stellar.org",
);
const tx = TransactionBuilder.fromXDR(signedXdr, Networks.TESTNET);

const send = await server.sendTransaction(tx);
if (send.status === "ERROR") {
throw new Error(
`Soroban error: ${JSON.stringify(send.errorResult)}`,
);
}

let result: rpc.Api.GetTransactionResponse | undefined;
for (let i = 0; i < 30; i++) {
await new Promise((r) => setTimeout(r, 2000));
result = await server.getTransaction(send.hash);
if (result.status !== rpc.Api.GetTransactionStatus.NOT_FOUND)
break;
}

if (
!result ||
result.status !== rpc.Api.GetTransactionStatus.SUCCESS
) {
throw new Error(
`Transaction ${result?.status ?? "TIMEOUT"}`,
);
}

const success =
result as rpc.Api.GetSuccessfulTransactionResponse;
try {
return success.returnValue
? Address.fromScVal(success.returnValue).toString()
: null;
} catch {
return null;
}
}

This file was deleted.

Loading