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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"@vitejs/plugin-react": "^4.5.0",
"@vitest/coverage-v8": "^4.1.9",
"autoprefixer": "^10.4.20",
"concurrently": "^9.2.1",
"http-server": "^14.1.1",
Expand All @@ -70,6 +71,7 @@
"tailwindcss": "^3.4.0",
"typescript": "^5.7.0",
"vite": "^6.3.0",
"vitest": "^4.1.9",
"wait-on": "^9.0.10"
},
"msw": {
Expand Down
3 changes: 3 additions & 0 deletions src/components/StellarMatchCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface StellarMatchCardProps {
withdrawHash: string | null;
feeBumpHash: string | null;
error: string;
retryStatus?: string;
showKey: boolean;
showSponsorPrompt: boolean;
onDestChange: (value: string) => void;
Expand All @@ -39,6 +40,7 @@ export function StellarMatchCard({
withdrawHash,
feeBumpHash,
error,
retryStatus = '',
showKey,
showSponsorPrompt,
onDestChange,
Expand Down Expand Up @@ -404,6 +406,7 @@ export function StellarMatchCard({
</div>
)}

{retryStatus && <p className="text-xs text-on-surface-variant">{retryStatus}</p>}
{error && <p className="text-xs text-error">{error}</p>}

{withdrawHash && (
Expand Down
69 changes: 56 additions & 13 deletions src/components/StellarReceive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { StellarReceiveView } from '@/components/StellarReceiveView';
import { useStealthLabels } from '@/hooks/useStealthLabels';
import { useStellarNotifications } from '@/hooks/useStellarNotifications';
import { STELLAR_NETWORK } from '@/config';
import { fetchWithRetry, withRetry, RetryExhaustedError } from '@/lib/stellar/retry';
import { useActivityStore } from '@/stores/activityStore';
import type { ImportResult } from '@/lib/stealthLabels';
import { KeyVault } from '@/vault';
Expand Down Expand Up @@ -65,6 +66,7 @@ function StellarMatchCardContainer({
const [withdrawHash, setWithdrawHash] = useState<string | null>(null);
const [feeBumpHash, setFeeBumpHash] = useState<string | null>(null);
const [error, setError] = useState('');
const [retryStatus, setRetryStatus] = useState('');
const [showKey, setShowKey] = useState(false);
const [showSponsorPrompt, setShowSponsorPrompt] = useState(false);

Expand All @@ -73,7 +75,12 @@ function StellarMatchCardContainer({
useEffect(() => {
(async () => {
try {
const res = await fetch(`${STELLAR_NETWORK.horizonUrl}/accounts/${match.stealthAddress}`);
const res = await fetchWithRetry(
`${STELLAR_NETWORK.horizonUrl}/accounts/${match.stealthAddress}`,
{},
{ onRetry: (attempt) => setRetryStatus(`Retrying (${attempt}/3)…`) },
);
setRetryStatus('');
if (!res.ok) {
setBalance('0');
return;
Expand All @@ -82,6 +89,7 @@ function StellarMatchCardContainer({
const xlm = data.balances?.find((b: { asset_type: string }) => b.asset_type === 'native');
setBalance(xlm?.balance ?? '0');
} catch {
setRetryStatus('');
setBalance('0');
} finally {
setBalanceState('loaded');
Expand All @@ -92,13 +100,21 @@ function StellarMatchCardContainer({
const handleWithdraw = async () => {
if (!dest) return;
setError('');
setRetryStatus('');
setWithdrawing(true);

const onRetry = (attempt: number) => setRetryStatus(`Retrying (${attempt}/3)…`);

try {
const horizonUrl = STELLAR_NETWORK.horizonUrl;
const networkPassphrase = STELLAR_NETWORK.networkPassphrase;

const res = await fetch(`${horizonUrl}/accounts/${match.stealthAddress}`);
const res = await fetchWithRetry(
`${horizonUrl}/accounts/${match.stealthAddress}`,
{},
{ onRetry },
);
setRetryStatus('');
if (!res.ok) throw new Error('Account not found');
const account = await res.json();

Expand Down Expand Up @@ -181,8 +197,10 @@ function StellarMatchCardContainer({
updateActivity(txHashHex, 'confirmed');
onWithdrawn();
} catch (err) {
setError(err instanceof Error ? err.message : 'Withdraw failed');
// In a real robust implementation we'd check if we submitted and mark failed
setRetryStatus('');
setError(
err instanceof RetryExhaustedError ? err.message : err instanceof Error ? err.message : 'Withdraw failed',
);
} finally {
setWithdrawing(false);
}
Expand All @@ -191,15 +209,22 @@ function StellarMatchCardContainer({
const handleSponsoredWithdraw = async () => {
if (!dest || !address) return;
setError('');
setRetryStatus('');
setWithdrawing(true);
setShowSponsorPrompt(false);

const onRetry = (attempt: number) => setRetryStatus(`Retrying (${attempt}/3)…`);

try {
const horizonUrl = STELLAR_NETWORK.horizonUrl;
const networkPassphrase = STELLAR_NETWORK.networkPassphrase;

// Fetch stealth account
const stealthRes = await fetch(`${horizonUrl}/accounts/${match.stealthAddress}`);
const stealthRes = await fetchWithRetry(
`${horizonUrl}/accounts/${match.stealthAddress}`,
{},
{ onRetry },
);
setRetryStatus('');
if (!stealthRes.ok) throw new Error('Stealth account not found');
const stealthAccount = await stealthRes.json();

Expand Down Expand Up @@ -233,7 +258,8 @@ function StellarMatchCardContainer({
innerTx.addSignature(match.stealthAddress, innerSignatureBase64);

// Fetch sponsor account for fee-bump
const sponsorRes = await fetch(`${horizonUrl}/accounts/${address}`);
const sponsorRes = await fetchWithRetry(`${horizonUrl}/accounts/${address}`, {}, { onRetry });
setRetryStatus('');
if (!sponsorRes.ok) throw new Error('Sponsor account not found');

// Build fee-bump transaction
Expand Down Expand Up @@ -282,7 +308,10 @@ function StellarMatchCardContainer({
updateActivity(txHashHex, 'confirmed');
onWithdrawn();
} catch (err) {
setError(err instanceof Error ? err.message : 'Sponsored withdraw failed');
setRetryStatus('');
setError(
err instanceof RetryExhaustedError ? err.message : err instanceof Error ? err.message : 'Sponsored withdraw failed',
);
} finally {
setWithdrawing(false);
}
Expand All @@ -299,6 +328,7 @@ function StellarMatchCardContainer({
withdrawHash={withdrawHash}
feeBumpHash={feeBumpHash}
error={error}
retryStatus={retryStatus}
showKey={showKey}
showSponsorPrompt={showSponsorPrompt}
onDestChange={setDest}
Expand Down Expand Up @@ -339,6 +369,7 @@ export function StellarReceive() {
}, []);
const [hasScanned, setHasScanned] = useState(false);
const [error, setError] = useState('');
const [retryStatus, setRetryStatus] = useState('');
const [isRegistering, setIsRegistering] = useState(false);
const [isRegSuccess, setIsRegSuccess] = useState(false);
const [regHash, setRegHash] = useState<string | null>(null);
Expand Down Expand Up @@ -407,7 +438,9 @@ export function StellarReceive() {
const soroban = new rpcMod.Server(STELLAR_NETWORK.rpcUrl);
const networkPassphrase = STELLAR_NETWORK.networkPassphrase;

const accountResponse = await soroban.getAccount(address);
const onRetry = (attempt: number) => setRetryStatus(`Retrying (${attempt}/3)…`);
const accountResponse = await withRetry(() => soroban.getAccount(address), { onRetry });
setRetryStatus('');
const sourceAccount = new Account(
accountResponse.accountId(),
accountResponse.sequenceNumber(),
Expand All @@ -425,11 +458,13 @@ export function StellarReceive() {
.setTimeout(30)
.build();

const simulated = await soroban.simulateTransaction(tx);
const simulated = await withRetry(() => soroban.simulateTransaction(tx), { onRetry });
setRetryStatus('');
if (!('error' in simulated) && 'result' in simulated) {
setIsAlreadyRegistered(true);
}
} catch {
setRetryStatus('');
// Not registered or contract not available
}
})();
Expand Down Expand Up @@ -636,12 +671,15 @@ export function StellarReceive() {
if (!stellarKeys || !address) return;
setIsRegistering(true);
setError('');
setRetryStatus('');
const onRetryReg = (attempt: number) => setRetryStatus(`Retrying (${attempt}/3)…`);
try {
const { rpc: rpcMod } = await import('@stellar/stellar-sdk');
const soroban = new rpcMod.Server(STELLAR_NETWORK.rpcUrl);
const networkPassphrase = STELLAR_NETWORK.networkPassphrase;

const accountResponse = await soroban.getAccount(address);
const accountResponse = await withRetry(() => soroban.getAccount(address), { onRetry: onRetryReg });
setRetryStatus('');
const sourceAccount = new Account(
accountResponse.accountId(),
accountResponse.sequenceNumber(),
Expand All @@ -664,7 +702,8 @@ export function StellarReceive() {
.setTimeout(30)
.build();

const simulated = await soroban.simulateTransaction(tx);
const simulated = await withRetry(() => soroban.simulateTransaction(tx), { onRetry: onRetryReg });
setRetryStatus('');
if ('error' in simulated) {
throw new Error((simulated as { error: string }).error || 'Simulation failed');
}
Expand Down Expand Up @@ -719,7 +758,10 @@ export function StellarReceive() {
}
}
} catch (err) {
setError(err instanceof Error ? err.message : 'Registration failed');
setRetryStatus('');
setError(
err instanceof RetryExhaustedError ? err.message : err instanceof Error ? err.message : 'Registration failed',
);
} finally {
setIsRegistering(false);
}
Expand Down Expand Up @@ -877,6 +919,7 @@ export function StellarReceive() {
hasScanned={hasScanned}
matchCount={matched.length}
error={error}
retryStatus={retryStatus}
onDeriveKeys={deriveKeysFromWallet}
onRegister={registerOnChain}
onScan={scanPayments}
Expand Down
4 changes: 4 additions & 0 deletions src/components/StellarReceiveView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface StellarReceiveViewProps {
matchCount: number;
matches: ReactNode;
error: string;
retryStatus?: string;
onDeriveKeys: () => void;
onRegister: () => void;
onScan: () => void;
Expand Down Expand Up @@ -59,6 +60,7 @@ export function StellarReceiveView({
matchCount,
matches,
error,
retryStatus = '',
onDeriveKeys,
onRegister,
onScan,
Expand Down Expand Up @@ -122,6 +124,7 @@ export function StellarReceiveView({
>
{isDerivingKeys ? 'Sign in wallet...' : 'Derive Keys'}
</button>
{retryStatus && <p className="text-sm text-on-surface-variant">{retryStatus}</p>}
{error && <p className="text-sm text-error">{error}</p>}
{vaultPanel}
</div>
Expand Down Expand Up @@ -253,6 +256,7 @@ export function StellarReceiveView({
)}
</div>

{retryStatus && <p className="text-sm text-on-surface-variant">{retryStatus}</p>}
{error && <p className="text-sm text-error">{error}</p>}

{/* Search, filter, and toolbar */}
Expand Down
Loading
Loading