Skip to content

useNetwork hook and Spacescan testnet links#786

Merged
Rigidity merged 4 commits into
xch-dev:mainfrom
dkackman:spacescan-testnet-links
May 24, 2026
Merged

useNetwork hook and Spacescan testnet links#786
Rigidity merged 4 commits into
xch-dev:mainfrom
dkackman:spacescan-testnet-links

Conversation

@dkackman
Copy link
Copy Markdown
Collaborator

This refactors mainnet/testnet url creation into a single urls file and a useNetwork hook, centralizing both rather than having url construction and testnet determination scattered through the fronend.

@Rigidity Rigidity merged commit a2b1975 into xch-dev:main May 24, 2026
6 of 8 checks passed
@dkackman
Copy link
Copy Markdown
Collaborator Author

Code review

Found 2 issues:

  1. ** always uses the mainnet Dexie API, even on testnet** — the function hardcodes false for isTestnet, while the sibling executeDexieSwap in the same file correctly threads the actual isTestnet value. On testnet, users receive mainnet swap quotes but submit testnet swaps, producing a price/liquidity mismatch.

sage/src/pages/Swap.tsx

Lines 370 to 385 in d9f74d9

receiveAssetId: string | null,
amount: string,
amountKind: 'pay' | 'receive',
) {
try {
const response = await fetch(
dexieApiUrl(
`v1/swap/quote?from=${payAssetId ?? 'XCH'}&to=${receiveAssetId ?? 'XCH'}&${amountKind === 'pay' ? 'from_amount' : 'to_amount'}=${amount || '0'}`,
false,
),
);
const data = await response.json();
return {
amount: (amountKind === 'pay'
? data.quote.to_amount
: data.quote.from_amount) as number,

  1. OfferCreationProgressDialog can upload offers to the wrong network during the loading window — the network && guard that prevented uploads while network state was unknown was removed. useNetwork initializes network as null and derives isTestnet: network !== 'mainnet', so isTestnet is true on the first render before getNetwork() resolves. If an upload triggers in that window on mainnet, it hits testnet marketplace endpoints. The guard should be restored as network !== null using the network value returned alongside isTestnet.

});
}, []);
return { network, isTestnet: network !== 'mainnet' };

// Handle uploads when offers are created
useEffect(() => {
if (createdOffers.length > 0 && !isProcessing && !isCanceling) {
let isMounted = true;

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@dkackman dkackman deleted the spacescan-testnet-links branch May 25, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants