Skip to content
Open
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
9 changes: 2 additions & 7 deletions frontend/src/app/streams/[id]/stream-details-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
resumeStream,
toBaseUnits,
toSorobanErrorMessage,
resolveTokenSymbol,
} from "@/lib/soroban";
import { CancelConfirmModal } from "@/components/stream-creation/CancelConfirmModal";
import type { BackendStreamEvent } from "@/lib/api-types";
Expand Down Expand Up @@ -51,12 +52,6 @@ interface StreamDetail {
const API_BASE_URL = `${getApiBaseUrl()}/v1`;
const EVENTS_PER_PAGE = 10;

const TOKEN_SYMBOLS: Record<string, string> = {
"CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCN": "XLM",
"CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA": "USDC",
"CCWAMYJME4YOIUNAKVYEBYOG5I65QMKEX2NMN4OJAPXRPIF24ONPSHY": "EURC",
};

const EVENT_STYLES: Record<string, { color: string; icon: string; label: string }> = {
CREATED: { color: "#22c55e", icon: "✓", label: "Created" },
TOPPED_UP: { color: "#3b82f6", icon: "+", label: "Topped Up" },
Expand Down Expand Up @@ -203,7 +198,7 @@ export default function StreamDetailsContent({ streamId }: { streamId: string })

const tokenSymbol = useMemo(() => {
if (!stream) return "??";
return TOKEN_SYMBOLS[stream.tokenAddress] || stream.tokenAddress.slice(0, 4);
return resolveTokenSymbol(stream.tokenAddress);
}, [stream]);

const handleWithdraw = async () => {
Expand Down
12 changes: 2 additions & 10 deletions frontend/src/lib/api/streams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BackendStream } from "@/lib/api-types";
import { TOKEN_ADDRESSES } from "@/lib/soroban";
import { TOKEN_ADDRESSES, resolveTokenSymbol } from "@/lib/soroban";

Check warning on line 2 in frontend/src/lib/api/streams.ts

View workflow job for this annotation

GitHub Actions / Frontend CI

'TOKEN_ADDRESSES' is defined but never used
import { shortenPublicKey } from "@/lib/wallet";
import {
DEFAULT_FETCH_TIMEOUT_MS,
Expand Down Expand Up @@ -33,14 +33,6 @@
data?: BackendStream[];
}

function resolveTokenLabel(tokenAddress: string): string {
const entry = Object.entries(TOKEN_ADDRESSES).find(
([, address]) => address === tokenAddress,
);

return entry?.[0] ?? `${tokenAddress.slice(0, 6)}...${tokenAddress.slice(-4)}`;
}

function toIncomingStreamStatus(stream: BackendStream): IncomingStreamStatus {
if (stream.isPaused) return "Paused";
if (stream.isActive) return "Active";
Expand All @@ -53,7 +45,7 @@
streamId: stream.streamId,
sender: stream.sender,
senderDisplay: shortenPublicKey(stream.sender),
token: resolveTokenLabel(stream.tokenAddress),
token: resolveTokenSymbol(stream.tokenAddress),
tokenAddress: stream.tokenAddress,
ratePerSecond: toTokenAmount(stream.ratePerSecond),
deposited: toTokenAmount(stream.depositedAmount),
Expand Down
16 changes: 2 additions & 14 deletions frontend/src/lib/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQuery } from "@tanstack/react-query";
import type { BackendStream } from "./api-types";
import { getStreamsEndpointCandidates, toTokenAmount } from "./api/_shared";
import { TOKEN_ADDRESSES } from "./soroban";
import { TOKEN_ADDRESSES, resolveTokenSymbol } from "./soroban";

Check warning on line 4 in frontend/src/lib/dashboard.ts

View workflow job for this annotation

GitHub Actions / Frontend CI

'TOKEN_ADDRESSES' is defined but never used
import { logger } from "./logger";

export interface ActivityItem {
Expand Down Expand Up @@ -64,18 +64,6 @@
return `${address.slice(0, 6)}...${address.slice(-4)}`;
}

/**
* Resolves a token contract address to its symbol (XLM/USDC/EURC), falling
* back to a shortened address when the token is unknown.
*/
function resolveTokenLabel(tokenAddress: string): string {
const entry = Object.entries(TOKEN_ADDRESSES).find(
([, address]) => address === tokenAddress,
);

return entry?.[0] ?? shortenAddress(tokenAddress);
}

/**
* Derives the display status from the backend flags. A paused stream reads
* "Paused"; an active one "Active". An inactive stream is "Cancelled" when a
Expand Down Expand Up @@ -137,7 +125,7 @@
id: s.streamId.toString(),
recipient: shortenAddress(counterparty),
amount: deposited,
token: resolveTokenLabel(s.tokenAddress),
token: resolveTokenSymbol(s.tokenAddress),
status: mapStreamStatus(s),
deposited,
withdrawn,
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/lib/soroban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ export function getTokenAddress(symbol: string): string {
return address;
}

/**
* Resolves a token contract address to its symbol (XLM/USDC/EURC), falling
* back to a shortened address when the token is unknown.
*/
export function resolveTokenSymbol(tokenAddress: string): string {
const entry = Object.entries(TOKEN_ADDRESSES).find(
([, address]) => address === tokenAddress,
);
if (entry) return entry[0];

if (!tokenAddress || tokenAddress.length < 10) return tokenAddress;
return `${tokenAddress.slice(0, 6)}...${tokenAddress.slice(-4)}`;
}

export async function fetchTokenBalance(
publicKey: string,
tokenSymbol: string,
Expand Down
Loading