XRPL Explorer

repository·main·Indexed 42 days ago

https://github.com/ripple/explorer

A web-based block explorer for the XRP Ledger (XRPL) built with Vite and React. Version 1.5.0 provides visibility into transactions and network activity, featuring a RESTful API under /api/v1, type-safe routing, and multi-language support.

Tokens
11.1K
Snippets
46
Records
57
Agent score
53%

What's inside XRPL Explorer

  1. Define typed routes with `RouteDefinition`

    main

    The explorer uses RouteDefinition to provide type safety for route parameters. A RouteDefinition object defines the URL path and uses a generic type to specify the expected shape of the parameters. This definition is then used by useRouteParams and RouteLink to ensure parameter names and types are correct at compile time.

    export const ACCOUNT_ROUTE: RouteDefinition<{
        id?: string
        tab?: 'assets' | 'transactions'
        assetType?: 'issued' | 'nfts'
    }> = {
        path: '/accounts/:id?/:tab?/:assetType?',
    }
  2. Define a new transaction type

    main

    To define how a transaction is displayed and processed in the Explorer, you must create an index.ts file within a directory named after the transaction type (e.g., ./Payment/index.ts).

    Each transaction definition requires several key properties to handle UI rendering, categorization, and data transformation:

    • Description: A React component for the "Description" section of the transaction's "Detailed" tab.
    • Simple: A React component for the left column of the transaction's "Simple" tab.
    • TableDetail: A React component for the transaction body when viewed on account, ledger, token, or NFT pages.
    • action: A TransactionCategory value used to determine the shape color of the transaction.
    • category: A TransactionCategory value used to determine the color of the transaction.
    • parser (optional): A function that accepts a transaction object and meta nodes, returning additional properties to be mapped onto the transaction. This is executed when a transaction is received from the server and is used to transform complex properties derived from nodes.

    Additionally, you must define a display value in /public/locales/en-US/translations.json using the key format: "transaction_{TransactionType}".

  3. How to add a new language to the application

    main

    To support a new language in the XRPL Explorer, follow these steps:

    1. Register the language: Add the new language code and its corresponding language name to the supportedLanguages map located in src/i18n/baseConfig.ts.
    2. Create the directory: Create a new folder inside public/locales/ named after the language code (e.g., ja-JP).
    3. Create the translation file: Add a file named translations.json inside your new language folder.
    4. Populate translations: Translate all entries in the JSON file. If you want the application to fall back to the English version for a specific key, set its value to null.
    /* Example structure for public/locales/ja-JP/translations.json */
    {
      "key_name": "日本語の翻訳",
      "another_key": null
    }
  4. Best practices for implementing analytics tracking

    main

    When implementing or debugging analytics in the explorer, follow these techniques:

    • Data Availability: Use the screen_view event only once the required data is available. For example, on a transaction page, wait until the transaction data is successfully retrieved before sending the event. This ensures you can include properties like transactionType in the same event rather than sending one event for the page visit and a second one for the data.
    • Page Views: Send the entire URL path for page view events; specific details can be parsed from the path during post-processing.
    • Debugging: Use the Adswerve browser plugin to debug analytics events.
    • Environment Usage: It is acceptable to use the production tracking ID on all servers, including local, dev, and staging. Data can be filtered or trimmed on the Google Analytics side.
  5. How to update existing translation entries

    main

    When modifying existing strings in en-US/translations.json, follow these rules to maintain localization quality:

    • Minor changes: If the meaning of the string does not change materially (e.g., adding a small clarification like "Please check your transaction hash" $\rightarrow$ "Please check your transaction hash or CTID"), you can leave the existing translations in other language files as they are.
    • Meaningful changes: If the entry's meaning changes significantly, you must set the value to null in all other translations.json files.

    Note: Setting a value to null triggers a fallback to the English version and serves as a signal to language contributors that a new localization is required.

  6. Install Google Tag Manager tracking code

    main

    To enable analytics, you must install Google Tag Manager by adding two snippets to your application.

    1. Paste the main script as high in the <head> of the page as possible.
    2. Paste the <noscript> snippet immediately after the opening <body> tag.
    <!-- Google Tag Manager (Head) -->
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    'https://www.googletagmanager.com/gtm.js?id='+i+dl;
    f.parentNode.insertBefore(j,f);})
    (window,document,'script','dataLayer','GTM-KCQZ3L8');</script>
    
    <!-- Google Tag Manager (Body) -->
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KCQZ3L8"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  7. How to add a new translation entry

    main

    When adding a new string to the application, you must ensure all supported languages are updated to prevent missing keys:

    1. Create the new entry in the base English file: en-US/translations.json.
    2. Add the same key to every other translations.json file in the public/locales/ directory.
    3. Set the value for these new keys to null in the non-English files. This ensures the application defaults to the English version instead of failing to find the key.
  8. Run and debug unit tests

    main

    Use the following commands to manage the test suite:

    • Watch mode: npm test
    • Coverage report: npm run test:coverage
    • View coverage: After running coverage, open coverage/index.html in your browser.

    Debugging in Chrome

    To debug a specific unit test using Chrome Developer Tools:

    1. Insert a debugger; statement in your test code.
    2. Run npm run test:debug.
    3. Open about:inspect in Chrome.
    4. Click the inspect link for the target process.
    5. Click the play button in Chrome DevTools to start execution; the test will pause at your debugger; statement.
    npm test
    npm run test:coverage
    npm run test:debug
  9. Install and run the XRPL Explorer

    main

    To set up the XRPL Explorer locally, ensure you have Node.js 22 and npm 8+ installed. Follow these steps:

    1. Install dependencies: npm install
    2. Configure environment: Copy the example environment file: cp .env.example .env
    3. Run in development mode: npm start
    4. Run in production mode: Build the project first, then start the production server: npm run build followed by npm run prod-server.
    # Development mode
    npm install
    cp .env.example .env
    npm start
    
    # Production mode
    npm install
    cp .env.example .env
    npm run build
    npm run prod-server
  10. Understand the server's routing and static file behavior

    main

    The server follows this request handling order:

    1. Compression: Responses are compressed using compression().
    2. JSON Parsing: Requests with JSON bodies are parsed via bodyParser.json().
    3. Static Files: Files from the /../build directory are served.
      • .html files are served with Cache-Control: no-cache.
      • Versioned files (matching the pattern .[0-9a-f]{20}.) are served with Cache-Control: max-age=31536000 (1 year).
    4. API Routes: All requests starting with /api/v1 are routed to the API handlers.
    5. Production SPA Fallback: If NODE_ENV is set to production, any request that does not match an API route or a static file is served the index.html file to support client-side routing.
    6. 404 Error: If no routes match and it is not in production mode, the server returns a 404 status with { "error": "route not found" }.
  11. Configure Testnet or Devnet mode

    main

    To run the explorer against a network other than the live net, modify your .env file with the following settings:

    Testnet mode

    • Set VITE_RIPPLED_HOST=s.altnet.rippletest.net
    • Set VITE_ENVIRONMENT=testnet (enables the TESTNET banner)

    Devnet mode

    • Set VITE_RIPPLED_HOST=s.devnet.rippletest.net
    • Set VITE_ENVIRONMENT=devnet (enables the TESTNET banner)
    # Testnet configuration
    VITE_RIPPLED_HOST=s.altnet.rippletest.net
    VITE_ENVIRONMENT=testnet
    
    # Devnet configuration
    VITE_RIPPLED_HOST=s.devnet.rippletest.net
    VITE_ENVIRONMENT=devnet