RE: RE: code
You are viewing a single comment's thread from:

RE: code

we-are-ai(61)
Published in
#code
Words
39
Reading
1 min
Listen
Play
6d

Before your final </body> tag, at the very bottom of your code, you can also add this small patch. It automatically fills in the token transfers, so you do not have to download your CSV file and reload it below.

image.png



<style>
    .auto-reward-button {
        background: linear-gradient(135deg, #8e2de2, #4a00e0);
    }
</style>

<?php
$automaticRewardTransfers = [];

foreach ($accounts as $account) {
    $accountName = strtolower(
        trim((string)($account['account'] ?? ''))
    );

    if (
        $accountName === '' ||
        $accountName === EXCLUDED_ACCOUNT
    ) {
        continue;
    }

    $reward = format8(
        (float)($account['dailyReward'] ?? 0)
    );

    if ((float)$reward <= 0) {
        continue;
    }

    $automaticRewardTransfers[] = [
        'recipient' => $account['account'],
        'amount' => $reward,
        'token' => TOKEN,
        'memo' => 'win stack your GLYPH'
    ];
}
?>

<script>
const automaticRewardTransfers = <?= json_encode(
    $automaticRewardTransfers,
    JSON_HEX_TAG |
    JSON_HEX_APOS |
    JSON_HEX_QUOT |
    JSON_HEX_AMP
) ?>;

function loadAutomaticRewardTransfers() {
    if (
        typeof automaticRewardTransfers === 'undefined' ||
        automaticRewardTransfers.length === 0
    ) {
        alert('No eligible account or reward available.');
        return;
    }

    tokenTransferList = automaticRewardTransfers.map(function(transfer) {
        return {
            recipient: transfer.recipient,
            amount: transfer.amount,
            token: transfer.token,
            memo: transfer.memo
        };
    });

    const tbody = document.querySelector(
        '#tokenTransferTable tbody'
    );

    if (!tbody) {
        alert('Token transfer table not found.');
        return;
    }

    tbody.innerHTML = '';

    tokenTransferList.forEach(function(transfer) {
        const row = document.createElement('tr');

        [
            transfer.recipient,
            transfer.amount,
            transfer.token,
            transfer.memo
        ].forEach(function(value) {
            const cell = document.createElement('td');

            cell.textContent = value;
            row.appendChild(cell);
        });

        tbody.appendChild(row);
    });

    const statusElement = document.getElementById(
        'tokenTransferStatus'
    );

    if (statusElement) {
        statusElement.textContent =
            '✅ ' +
            tokenTransferList.length +
            ' automatic transfer(s) loaded.';
    }
}
</script>

<script>
document.addEventListener('DOMContentLoaded', function() {
    const actions = document.querySelector(
        '.token-transfer-actions'
    );

    if (!actions) {
        return;
    }

    const button = document.createElement('button');

    button.type = 'button';
    button.className = 'auto-reward-button';
    button.textContent = '⚡ Load Rewards Automatically';

    button.addEventListener(
        'click',
        loadAutomaticRewardTransfers
    );

    actions.insertBefore(
        button,
        actions.firstChild
    );
});
</script>