+page.svelte 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <script>
  2. import Header from '$lib/layout/Header.svelte';
  3. import StatsCard from '$lib/components/StatsCard.svelte';
  4. import PaymentMenu from '$lib/components/wallet/PaymentMenu.svelte';
  5. import SellMenu from '$lib/components/wallet/SellMenu.svelte';
  6. import tokensIcon from '$lib/assets/icons/sidebar/tokens.svg?raw';
  7. import walletIcon from '$lib/assets/icons/sidebar/wallet.svg?raw';
  8. const breadcrumb = [{ label: 'Início' }, { label: 'wallet', active: true }];
  9. let easyTokens = [
  10. { id: 1, label: 'EasyToken Soja', amount: 1 },
  11. { id: 2, label: 'EasyToken Milho', amount: 1 },
  12. { id: 3, name: 'EasyToken Café', balance: 1 }
  13. ];
  14. let easyCoinBalance = 0;
  15. let isPaymentOpen = false;
  16. let isSellOpen = false;
  17. let rateBRLPerEasyCoin = 100;
  18. function openPayment() { isPaymentOpen = true; }
  19. function closePayment() { isPaymentOpen = false; }
  20. function confirmPayment(method) { isPaymentOpen = false; }
  21. function openSell() { isSellOpen = true; }
  22. function closeSell() { isSellOpen = false; }
  23. function confirmSell(e) {
  24. isSellOpen = false;
  25. }
  26. function formatToken(n) {
  27. return new Intl.NumberFormat('pt-BR', { minimumFractionDigits: 0, maximumFractionDigits: 6 }).format(Number(n || 0));
  28. }
  29. function formatCoin(n) {
  30. return new Intl.NumberFormat('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(Number(n || 0));
  31. }
  32. </script>
  33. <div>
  34. <Header title="Wallet" subtitle="Saldos e operações" breadcrumb={breadcrumb} />
  35. <div class="p-4 space-y-6">
  36. <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
  37. {#each easyTokens as t}
  38. <div class="rounded-lg overflow-hidden">
  39. <StatsCard
  40. title={t.label || t.name || 'EasyToken'}
  41. value={formatToken(t.amount || t.balance || 0)}
  42. change="Saldo atual"
  43. iconSvg={tokensIcon}
  44. />
  45. </div>
  46. {/each}
  47. <div class="rounded-lg overflow-hidden">
  48. <StatsCard
  49. title="EasyCoin"
  50. value={formatCoin(easyCoinBalance)}
  51. change="Saldo atual"
  52. iconSvg={walletIcon}
  53. />
  54. </div>
  55. </div>
  56. <div class="flex gap-3">
  57. <button
  58. class="inline-flex items-center gap-2 px-4 py-2 rounded-md bg-blue-600 hover:bg-blue-700 text-white shadow"
  59. on:click={openPayment}
  60. >
  61. Comprar EasyCoins
  62. </button>
  63. <button
  64. class="inline-flex items-center gap-2 px-4 py-2 rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700 text-gray-800 dark:text-gray-100"
  65. on:click={openSell}
  66. >
  67. Vender EasyCoins
  68. </button>
  69. </div>
  70. </div>
  71. <PaymentMenu
  72. isOpen={isPaymentOpen}
  73. onClose={closePayment}
  74. onConfirm={confirmPayment}
  75. />
  76. <SellMenu
  77. isOpen={isSellOpen}
  78. onClose={closeSell}
  79. onConfirm={(e) => confirmSell(e.detail || e)}
  80. rateBRLPerEasyCoin={rateBRLPerEasyCoin}
  81. />
  82. </div>