Closes #132
Before any bet involving a custom Stellar asset is submitted, the system automatically checks whether the connected wallet has the required trustline. If not, a one-click modal guides the user through setting it up via Freighter β then resumes the bet automatically.
Any custom Stellar asset can be attached to a market via the asset field:
// Market shape
{
asset: { code: "USDC", issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN" }
}Native XLM markets (asset field absent or code: "XLM") skip the check entirely.
User clicks "Bet"
β
βΌ
market.asset present?
No βββββββββββββββββββββββββββββββββββββββΊ Submit bet directly
Yes
β
βΌ
wallet connected?
No βββββββββββββββββββββββββββββββββββββββΊ Show "Connect Wallet" modal
Yes
β
βΌ
GET horizon-testnet.stellar.org/accounts/:wallet
β
ββ Timeout (10s) βββββββββββββββββββΊ Show "Network Timeout" modal + Retry button
ββ HTTP 404 βββββββββββββββββββΊ hasTrustline = false β show trustline modal
ββ HTTP 5xx βββββββββββββββββββΊ Show error modal
β
βΌ
balances[] contains { asset_code, asset_issuer }?
Yes βββββββββββββββββββββββββββββββββββββββΊ Submit bet directly (no modal)
No
β
βΌ
Show TrustlineModal: "Your wallet needs to trust [ASSET]"
β
User clicks "Set Up Trustline"
β
βΌ
buildTrustlineXdr(wallet, asset)
β TransactionBuilder + Operation.changeTrust
β 30s timeout, 100 stroops fee, TESTNET passphrase
β
βΌ
window.freighter.signTransaction(xdr, { network: "TESTNET" })
β
βΌ
submitTrustlineTx(signedXdr)
β Horizon.Server.submitTransaction
β
βΌ
Trustline confirmed βββββββββββββββββββββββΊ Resume original bet submission
| Scenario | Behaviour |
|---|---|
| Wallet not connected | "Connect Wallet" prompt shown |
| Horizon timeout (>10s) | "Network Timeout" modal with Retry button |
| Account not funded (404) | Treated as no trustline β modal shown |
| User cancels Freighter | Error modal with Dismiss |
| Trustline already exists | Modal never shown, bet proceeds immediately |
| XLM / native asset | Check skipped entirely |
| File | Purpose |
|---|---|
frontend/src/utils/trustline.ts |
hasTrustline, buildTrustlineXdr, submitTrustlineTx |
frontend/src/hooks/useTrustline.ts |
Orchestration hook |
frontend/src/components/TrustlineModal.tsx |
UI modal for all states |
frontend/src/utils/__tests__/trustline.test.ts |
Unit tests (>90% coverage) |