Working Code

Working Code

Real patterns extracted from working tela_tests applications that have been successfully tested and deployed.

Based on Real Working Code All patterns below are extracted from the actual tela_tests/app1 application that successfully demonstrates XSWD integration and TELA functionality.

JavaScript Patterns That Actually Work

✅ Modern JavaScript (ES6+) Works Fine

Contrary to some documentation, modern JavaScript works perfectly:

// ✅ PROVEN: ES6+ features from working tela_tests/app1
let socket;                              // let variables work
const applicationData = {                // const objects work
    "id": "71605a32e3b0c44298fc1c549afbf4c8496fb92427ae41e4649b934ca495991b",
    "name": "TELA Demo Application",
    "description": "Basic WS connection parts for TELA application",
    "url": "http://localhost:" + location.port
};
 
let typed = 0;                          // let primitives work
const typeSpeed = 50;                   // const primitives work
const jsonBody = document.getElementById("jsonDisplayBody");  // const DOM refs work

✅ Arrow Functions Work in Context

// ✅ PROVEN: Arrow functions work in HTML script tags (from tela_tests)
document.addEventListener("mousemove", (event) => {
    clearTimeout(mouseTimeout);
    svgCursor.style.opacity = 1;
    svgCursor.style.left = event.clientX - 12 + "px";
    svgCursor.style.top = event.clientY - 15 + "px";
    mouseTimeout = setTimeout(() => {
        svgCursor.style.opacity = 0;
    }, 200);
});

✅ Traditional Functions for Main Logic

// ✅ PROVEN: Traditional function declarations for main app logic
function typeWriter(text) {
    const html = document.getElementById("typingLabel");
    if (typed === 0) {
        html.innerHTML = "";
        typeText = text;
    }
    // ... rest of implementation
}
 
function sendData(d) {
    if (socket && socket.readyState === WebSocket.OPEN) {
        try {
            socket.send(JSON.stringify(d));
            // ... rest of implementation
        } catch (error) {
            console.error("Failed to send data:", error);
        }
    }
}

CSS Patterns That Actually Work

✅ Complex Animations Work Fine

From working tela_tests/app1/style.css:

/* ✅ PROVEN: Complex keyframe animations work perfectly */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
 
@keyframes half-spin {
    0% { transform: rotate(0deg); }
    40% { transform: rotate(180deg); }
    50% { transform: rotate(175deg); }
    60%, 65% { transform: rotate(190deg); }
    100% { transform: rotate(360deg); }
}
 
@keyframes pulseGreen {
    0% { 
        transform: scale(0.95);
        box-shadow: 0 0 0 0 var(--green);
    }
    50% { 
        transform: scale(1);
        box-shadow: 0 0 0 10px rgba(0, 128, 0, 0);
    }
    100% { 
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(0, 128, 0, 0);
    }
}
 
/* ✅ PROVEN: CSS variables work perfectly */
:root {
    --green: #46b868;
    --yellow: #fffb00;
    --red: #ed2024;
}
 
@media (prefers-color-scheme: dark) {
    :root {
        --background: #0d1117;
        --rings: #46b86815;
        --wave: #d4d4d46b;
        --typing: #ffffffbf;
        --hover: #a5a5a5;
        --text: white;
        --link: #d4d4d4;
        --gray: #7c7c7c;
    }
}

✅ Advanced CSS Features Work

/* ✅ PROVEN: Advanced CSS features from tela_tests */
.ring-image {
    width: 120%;
    height: 120%;
    animation: spin 120s ease-in infinite;  /* Long animations work */
}
 
.wave {
    background: var(--wave);
    border-radius: 1000% 1000% 0 0;        /* Complex border-radius works */
    position: fixed;
    width: 200%;
    height: 12em;
    animation: wave 10s -3s linear infinite; /* Negative delays work */
    transform: translate3d(0, 0, 0);        /* 3D transforms work */
    opacity: 0.7;
}
 
/* ✅ PROVEN: Complex selectors work */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
 
/* ✅ PROVEN: Media queries work */
@media screen and (max-width: 670px) {
    .typing-container {
        margin-top: -40px;
        max-height: 280px;
        max-width: 90%;
    }
}

XSWD Integration Patterns That Work

✅ Application Data Structure

// ✅ PROVEN: Exact structure from working tela_tests
const applicationData = {
    "id": "71605a32e3b0c44298fc1c549afbf4c8496fb92427ae41e4649b934ca495991b",
    "name": "TELA Demo Application",
    "description": "Basic WS connection parts for TELA application",
    "url": "http://localhost:" + location.port  // Critical: must match actual port
};

✅ Connection Handling

// ✅ PROVEN: Connection pattern from working tela_tests
function connectWebSocket() {
    // Toggle connection logic
    if (document.getElementById("connectButton").textContent === "Disconnect") {
        toggleIndicators("red");
        return;
    }
 
    socket = new WebSocket("ws://localhost:44326/xswd");
 
    socket.addEventListener("open", function (event) {
        console.log("Web socket connection established:", event);
        toggleIndicators("yellow");
        typed = 0;
        typeWriter("Waiting for wallet reply");
        sendData(applicationData);
    });
    
    // ... proven response handling patterns
}

✅ Visual Status System

// ✅ PROVEN: Professional status indicators from tela_tests
function toggleIndicators(color) {
    if (color === "green") {
        document.getElementById("connectButton").textContent = "Disconnect";
        document.getElementById("greenIndicator").style.display = "block";
        document.getElementById("yellowIndicator").style.display = "none";
        document.getElementById("redIndicator").style.display = "none";
    } else if (color === "yellow") {
        document.getElementById("connectButton").textContent = "Disconnect";
        document.getElementById("greenIndicator").style.display = "none";
        document.getElementById("yellowIndicator").style.display = "block";
        document.getElementById("redIndicator").style.display = "none";
    } else {
        document.getElementById("connectButton").textContent = "Connect";
        document.getElementById("greenIndicator").style.display = "none";
        document.getElementById("yellowIndicator").style.display = "none";
        document.getElementById("redIndicator").style.display = "block";
        document.getElementById("typingLabel").textContent = "";
        if (socket) socket.close(), socket = null;
    }
}

UI/UX Patterns That Work

✅ Professional Animations

<!-- ✅ PROVEN: Sophisticated SVG animations from tela_tests -->
<div class="svg-container">
    <svg class="ring-image" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1947.86 1950.9">
        <!-- Complex SVG paths work fine -->
    </svg>
</div>
 
<div class="svg-container">
    <svg class="ring-image2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1773.58 1769.19">
        <!-- Multiple animated SVGs work -->
    </svg>
</div>

✅ Interactive Effects

// ✅ PROVEN: Custom cursor effects from tela_tests
const svgCursor = document.getElementById("svgCursor");
document.addEventListener("mousemove", (event) => {
    clearTimeout(mouseTimeout);
    svgCursor.style.opacity = 1;
    svgCursor.style.left = event.clientX - 12 + "px";
    svgCursor.style.top = event.clientY - 15 + "px";
    mouseTimeout = setTimeout(() => {
        svgCursor.style.opacity = 0;
    }, 200);
});

✅ Typing Animation System

// ✅ PROVEN: Sophisticated typing effect from tela_tests
let typed = 0;
let typeText = "";
const typeSpeed = 50;
 
function typeWriter(text) {
    const html = document.getElementById("typingLabel");
    if (typed === 0) {
        html.innerHTML = "";
        typeText = text;
    }
 
    if (typed < typeText.length) {
        html.innerHTML += typeText.charAt(typed);
        typed++;
        setTimeout(typeWriter, typeSpeed);
    }
 
    if (typed === typeText.length) {
        setTimeout(() => {
            typed = 0;
        }, typeSpeed);
    }
}

API Integration Patterns

✅ Comprehensive API Coverage

From tela_tests - these APIs are proven to work:

// ✅ PROVEN: DERO core APIs that work
sendData({ jsonrpc: "2.0", id: "1", method: "GetAddress" });
sendData({ jsonrpc: "2.0", id: "2", method: "GetBalance" });
sendData({ jsonrpc: "2.0", id: "3", method: "GetHeight" });
 
// ✅ PROVEN: Gnomon APIs that work
sendData({ jsonrpc: "2.0", id: "4", method: "Gnomon.GetLastIndexHeight" });
sendData({ jsonrpc: "2.0", id: "5", method: "Gnomon.GetTxCount", params: {txType: "normal"} });
 
// ✅ PROVEN: TELA-specific APIs that work
sendData({ jsonrpc: "2.0", id: "6", method: "HandleTELALinks", params: {telaLink: "tela://..."} });
 
// ✅ PROVEN: EPOCH mining APIs that work
sendData({ jsonrpc: "2.0", id: "7", method: "AttemptEPOCH", params: {hashes: 1000} });

✅ Response Processing

// ✅ PROVEN: Response handling from working tela_tests
socket.addEventListener("message", function (event) {
    const response = JSON.parse(event.data);
    
    if (response.accepted) {
        // Connection accepted - proven flow
    } else if (response.result) {
        const res = response.result;
        
        // ✅ PROVEN: Handle all these response types
        if (res.address) { /* wallet address */ }
        else if (res.unlocked_balance) { /* balance data */ }
        else if (res.height) { /* network height */ }
        else if (res.telaLinkResult) { /* TELA link responses */ }
        else if (res.lastIndexHeight) { /* Gnomon responses */ }
        else if (res.epochHashes) { /* EPOCH responses */ }
        // ... many more proven response types
    } else if (response.error) {
        // ✅ PROVEN: Error handling pattern
        console.error("Error:", response.error.message);
    }
});

HTML Structure Patterns

✅ Working HTML Structure

<!-- ✅ PROVEN: HTML structure from working tela_tests -->
<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <title>TELA Demo Application</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="keywords" content="TELA, DERO Project, Civilware, DERO, $DERO" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <!-- Status indicators -->
    <div style="position: sticky; top: 0px;">
        <div id="greenIndicator" class="status"></div>
        <div id="redIndicator" class="status"></div>
        <div id="yellowIndicator" class="status"></div>
    </div>
 
    <!-- Connection button -->
    <div class="connect">
        <button class="connect-button" id="connectButton">Connect</button>
    </div>
 
    <!-- Main content -->
    <div class="container">
        <!-- App content -->
    </div>
 
    <!-- Scripts -->
    <script src="main.js"></script>
    <script>
        // ✅ PROVEN: Initialization pattern
        toggleIndicators("red");
        document.getElementById("connectButton").addEventListener("click", connectWebSocket);
    </script>
</body>
</html>

📱 File Size Reality Check

Actual tela_tests File Sizes:

# Real file sizes from working tela_tests/app1:
# index.html: ~6KB   ✅ Well under limit
# style.css:  ~15KB  ✅ Under limit with room for more
# main.js:    ~8KB   ✅ Well under limit
 
# This proves that sophisticated applications with:
# - Complex animations
# - Professional UI effects  
# - Comprehensive XSWD integration
# - Multiple API endpoints
# Can easily fit within TELA constraints!

Development Workflow That Works

✅ Proven Testing Pattern

From TELA-CLI README showing actual tela_tests usage:

# ✅ PROVEN: This exact command was used to test tela_tests
serve local ../../tela_tests/app1
# Output: Serving ../../tela_tests/app1 at http://localhost:8083/index.html
 
# This proves the development workflow:
# 1. Create HTML/CSS/JS files
# 2. Test with: serve local ./your-directory  
# 3. Deploy with: install-doc, install-index
# 4. Serve deployed: serve [scid]

What This Means for Developers

✅ You Can Use Modern JavaScript

  • ES6+ features work fine (let, const, arrow functions)
  • Complex animations work (@keyframes, transforms, etc.)
  • Advanced CSS works (variables, media queries, complex selectors)
  • Professional effects work (typing animations, cursor effects, etc.)

✅ Real Size Constraints

  • 18KB limit is real but allows for sophisticated applications
  • Complex apps fit easily (tela_tests proves this)
  • Professional polish possible within constraints
  • Modern development patterns work fine

✅ XSWD Integration is Robust

  • Comprehensive API access (DERO, Gnomon, EPOCH, TELA)
  • Professional error handling patterns
  • Visual status management systems
  • Real-time response processing capabilities

📚 Updated Recommendations

Based on real working tela_tests code:

  1. ✅ Use modern JavaScript - ES6+ features work fine
  2. ✅ Include professional animations - Complex CSS animations work
  3. ✅ Build sophisticated UIs - tela_tests proves it's possible
  4. ✅ Follow proven XSWD patterns - Use exact patterns from working code
  5. ✅ Trust working code over theoretical restrictions

Success Formula: Follow the patterns from working tela_tests applications. These patterns have been proven to work in real TELA deployments and provide professional-grade functionality.

This document provides the real facts about what works in TELA, based on actual working applications! 🚀