feat: redesign home, market, wallet, and settings screens
Frontend CI / unit (test, type-check, build) (push) Failing after 1m25s
Frontend CI / browser E2E (frontend + pinned backend) (push) Skipped

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-26 14:54:44 +03:30
co-authored by Cursor
parent 83cc9a61f9
commit 8a311c1fd5
16 changed files with 937 additions and 672 deletions
+321 -428
View File
@@ -1,529 +1,422 @@
<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import { Minus, Plus, TrendingUp } from 'lucide-vue-next'
import PageBackButton from '@/components/common/PageBackButton.vue'
import { TrendingUp, Heart } from 'lucide-vue-next'
import AppModal from '@/components/common/AppModal.vue'
import MarketChart from '@/components/market/MarketChart.vue'
import { useUserStore } from '@/stores/user'
import { useWalletStore } from '@/stores/wallet'
import { useMarketStore, type TimeRange } from '@/stores/market'
import { formatNumber, formatDecimal, formatCurrency, formatPercent } from '@/utils/storage'
import { formatNumber, formatDecimal, formatPercent } from '@/utils/storage'
import { tomansForGoldPurchase, tomansForGoldSale } from '@/utils/goldTrade'
import { useToast } from '@/composables/useToast'
import { illustrations } from '@/assets/illustrations'
const router = useRouter()
const userStore = useUserStore()
const walletStore = useWalletStore()
const marketStore = useMarketStore()
const toast = useToast()
const timeRanges: { key: TimeRange; label: string }[] = [
{ key: '1d', label: '۱ روز' },
{ key: '7d', label: '۷ روز' },
{ key: '30d', label: '۳۰ روز' },
{ key: '90d', label: '۹۰ روز' },
{ key: '7d', label: '۱ هفته' },
{ key: '30d', label: '۱ ماه' },
{ key: '90d', label: '۳ ماه' },
{ key: '1y', label: '۱ سال' },
]
const showBuyModal = ref(false)
const showSellModal = ref(false)
const tradeGrams = ref(1)
const tradeBuyEstimate = computed(() => {
const g = Number(tradeGrams.value)
if (!Number.isFinite(g) || g <= 0) return null
return tomansForGoldPurchase(g)
})
const tradeSellEstimate = computed(() => {
const g = Number(tradeGrams.value)
if (!Number.isFinite(g) || g <= 0) return null
return tomansForGoldSale(g)
})
const assetValue = computed(() => walletStore.goldGrams * marketStore.currentPrice)
const tradeMode = ref<'buy' | 'sell'>('buy')
const tradeGrams = ref(0.1)
const submitting = ref(false)
function openBuy() { tradeGrams.value = 1; showBuyModal.value = true }
function openSell() { tradeGrams.value = 1; showSellModal.value = true }
const tradeEstimate = computed(() => {
const grams = Number(tradeGrams.value)
if (!Number.isFinite(grams) || grams <= 0) return null
return tradeMode.value === 'buy' ? tomansForGoldPurchase(grams) : tomansForGoldSale(grams)
})
async function confirmBuy() {
const result = await walletStore.buyGold(tradeGrams.value, marketStore.currentPrice)
result.success ? (toast.success(result.message), showBuyModal.value = false) : toast.error(result.message)
const gramLabel = computed(() => formatDecimal(tradeGrams.value, 1).replace('٫', '/').replace('.', '/'))
function stepGrams(direction: -1 | 1) {
const next = Math.round((tradeGrams.value + direction * 0.1) * 10) / 10
tradeGrams.value = Math.min(100, Math.max(0.1, next))
}
async function confirmSell() {
const result = await walletStore.sellGold(tradeGrams.value, marketStore.currentPrice)
result.success ? (toast.success(result.message), showSellModal.value = false) : toast.error(result.message)
async function submitTrade() {
if (submitting.value) return
submitting.value = true
try {
const result =
tradeMode.value === 'buy'
? await walletStore.buyGold(tradeGrams.value, marketStore.currentPrice)
: await walletStore.sellGold(tradeGrams.value, marketStore.currentPrice)
result.success ? toast.success(result.message) : toast.error(result.message)
} finally {
submitting.value = false
}
}
</script>
<template>
<div class="market-page">
<!-- Header -->
<header class="market-header card-enter">
<PageBackButton @click="router.push('/')" />
<div class="market-header__title">
<img :src="illustrations.goldBar" alt="" class="market-header__title-icon" aria-hidden="true" />
<h1>بازار طلا</h1>
</div>
<div class="market-header__coins">
<img :src="illustrations.coinLarge" alt="" class="market-header__coin-icon" aria-hidden="true" />
<span>{{ formatNumber(userStore.coins) }}</span>
</div>
</header>
<!-- Price + Chart -->
<section class="price-section card-enter" style="animation-delay:0.04s">
<p class="price-section__label">قیمت هر گرم طلا</p>
<p class="price-section__amount">{{ formatNumber(marketStore.currentPrice) }}</p>
<div class="price-section__meta">
<span class="price-section__unit">تومان</span>
<span class="price-section__change">
<TrendingUp :size="14" stroke-width="2.5" />
{{ formatPercent(marketStore.dailyChange) }} (امروز)
</span>
</div>
<MarketChart />
<div class="time-filters">
<button
v-for="range in timeRanges"
:key="range.key"
class="time-filter"
:class="{ 'time-filter--active': marketStore.selectedRange === range.key }"
@click="marketStore.setRange(range.key)"
>
{{ range.label }}
</button>
</div>
<section class="market-hero">
<img :src="illustrations.marketHero" alt="" class="market-hero__img" />
<header class="market-header">
<PageBackButton @click="router.push('/')" />
<div class="market-header__copy" />
<span class="market-header__spacer" aria-hidden="true" />
</header>
</section>
<!-- Buy / Sell -->
<div class="trade-buttons card-enter" style="animation-delay:0.08s">
<button type="button" class="trade-btn trade-btn--buy" @click="openBuy">خرید</button>
<button type="button" class="trade-btn trade-btn--sell" @click="openSell">فروش</button>
</div>
<!-- Assets -->
<section class="asset-card card-enter" style="animation-delay:0.12s">
<div class="asset-card__info">
<div class="asset-card__title">
<Heart :size="14" fill="#f4ae21" color="#f4ae21" aria-hidden="true" />
<span>دارایی من</span>
<div class="market-body">
<section class="price-card">
<div class="price-card__top">
<img :src="illustrations.goldBarsStack" alt="" class="price-card__gold" />
<div class="price-card__main">
<p class="price-card__label">قیمت هر گرم طلای آموزشی</p>
<p class="price-card__amount">{{ formatNumber(marketStore.currentPrice) }}</p>
<p class="price-card__unit">سکه آموزشی</p>
</div>
<div class="price-card__change" :class="{ 'price-card__change--down': marketStore.dailyChange < 0 }">
<span>
<TrendingUp :size="14" />
{{ formatPercent(marketStore.dailyChange) }}
</span>
<small>در ۲۴ ساعت گذشته</small>
</div>
</div>
<p class="asset-card__grams">
{{ formatDecimal(walletStore.goldGrams) }}
<span class="asset-card__unit">گرم</span>
</p>
<p class="asset-card__value">
<img :src="illustrations.coinLarge" alt="" class="asset-card__coin" aria-hidden="true" />
<span>{{ formatNumber(assetValue) }}</span>
<span class="asset-card__value-unit">تومان</span>
</p>
</div>
<img
:src="illustrations.treasureChest"
alt=""
class="asset-card__chest"
aria-hidden="true"
/>
</section>
<AppModal :open="showBuyModal" title="خرید طلا" @close="showBuyModal = false">
<div class="trade-form">
<label class="trade-form__label">مقدار (گرم)</label>
<input
v-model.number="tradeGrams"
type="number"
min="0.000001"
step="0.000001"
class="trade-form__input"
dir="ltr"
/>
<p class="trade-form__cost">
<template v-if="tradeBuyEstimate != null">
برآورد هزینه (خرید به بالا): {{ formatCurrency(tradeBuyEstimate) }}
</template>
<template v-else>مقدار نامعتبر</template>
</p>
<p class="trade-form__hint">مبلغ نهایی پس از تأیید از سرور ثبت می‌شود.</p>
<p class="trade-form__balance">موجودی: {{ formatCurrency(walletStore.cash) }}</p>
</div>
<template #footer>
<button type="button" class="trade-btn trade-btn--buy trade-btn--modal" @click="confirmBuy">
تأیید خرید
</button>
</template>
</AppModal>
<MarketChart />
<AppModal :open="showSellModal" title="فروش طلا" @close="showSellModal = false">
<div class="trade-form">
<label class="trade-form__label">مقدار (گرم)</label>
<input
v-model.number="tradeGrams"
type="number"
min="0.000001"
step="0.000001"
class="trade-form__input"
dir="ltr"
/>
<p class="trade-form__cost">
<template v-if="tradeSellEstimate != null">
برآورد دریافتی (فروش به پایین): {{ formatCurrency(tradeSellEstimate) }}
</template>
<template v-else>مقدار نامعتبر</template>
</p>
<p class="trade-form__hint">مبلغ نهایی پس از تأیید از سرور ثبت می‌شود.</p>
<p class="trade-form__balance">طلای موجود: {{ formatDecimal(walletStore.goldGrams) }} گرم</p>
</div>
<template #footer>
<button type="button" class="trade-btn trade-btn--sell trade-btn--modal" @click="confirmSell">
تأیید فروش
<div class="time-filters">
<button
v-for="range in timeRanges"
:key="range.key"
type="button"
class="time-filter"
:class="{ 'time-filter--active': marketStore.selectedRange === range.key }"
@click="marketStore.setRange(range.key)"
>
{{ range.label }}
</button>
</div>
</section>
<div class="trade-switch">
<button
type="button"
class="trade-switch__btn"
:class="{ 'trade-switch__btn--active': tradeMode === 'buy' }"
@click="tradeMode = 'buy'"
>
خرید طلا
</button>
</template>
</AppModal>
<button
type="button"
class="trade-switch__btn"
:class="{ 'trade-switch__btn--active': tradeMode === 'sell' }"
@click="tradeMode = 'sell'"
>
فروش طلا
</button>
</div>
<div class="amount-card">
<span>مقدار (گرم)</span>
<div class="amount-card__stepper">
<button type="button" aria-label="کم کردن" @click="stepGrams(-1)"><Minus :size="18" /></button>
<strong>{{ gramLabel }}</strong>
<button type="button" aria-label="زیاد کردن" @click="stepGrams(1)"><Plus :size="18" /></button>
</div>
</div>
<p class="estimate">
<span>مبلغ تقریبی</span>
<strong>{{ tradeEstimate == null ? '—' : formatNumber(tradeEstimate) }}</strong>
</p>
<button type="button" class="trade-submit" :disabled="submitting" @click="submitTrade">
{{ tradeMode === 'buy' ? 'خرید طلا' : 'فروش طلا' }}
</button>
</div>
</div>
</template>
<style scoped>
.market-page {
position: relative;
min-height: 100dvh;
padding: 0 var(--page-padding) calc(var(--nav-height) + var(--nav-bottom-offset) + env(safe-area-inset-bottom, 0px) + 16px);
}
/* ── Header ── */
.market-header {
display: grid;
grid-template-columns: 40px 1fr auto;
align-items: center;
direction: rtl;
gap: 8px;
height: 52px;
margin-bottom: 18px;
padding-top: 4px;
}
.market-header :deep(.page-back-btn) {
grid-column: 1;
justify-self: start;
}
.market-header__title {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
direction: rtl;
}
.market-header__title-icon {
width: 28px;
height: 28px;
object-fit: contain;
flex-shrink: 0;
}
.market-header__title h1 {
font-size: 1.125rem;
font-weight: 800;
color: var(--text-main);
white-space: nowrap;
}
.market-header__coins {
grid-column: 3;
justify-self: end;
display: inline-flex;
align-items: center;
gap: 6px;
min-height: 34px;
padding: 5px 12px 5px 10px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.08);
font-size: 0.8125rem;
font-weight: 800;
color: var(--text-main);
}
.market-header__coin-icon {
width: 20px;
height: 20px;
object-fit: contain;
}
/* ── Price section ── */
.price-section {
margin-bottom: 16px;
padding: 16px 14px 14px;
background: transparent;
border: 1px solid rgba(174, 185, 210, 0.28);
border-radius: 22px;
padding-bottom: calc(var(--nav-height) + var(--nav-bottom-offset) + env(safe-area-inset-bottom, 0px) + 16px);
}
.price-section__label {
text-align: center;
font-size: 0.8125rem;
font-weight: 600;
color: var(--text-muted);
margin-bottom: 8px;
.market-hero {
position: relative;
height: 230px;
}
.price-section__amount {
.market-hero__img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100dvh;
object-fit: cover;
object-position: center top;
z-index: 0;
}
.market-header {
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: 1;
display: grid;
grid-template-columns: 40px 1fr 40px;
align-items: start;
padding: 8px 10px 0;
direction: rtl;
}
.market-header__copy {
text-align: center;
font-size: clamp(1.75rem, 7vw, 2rem);
}
.market-header__copy h1 {
margin: 0;
color: #fff;
font-size: 1.2rem;
font-weight: 800;
color: var(--gold);
line-height: 1.1;
margin-bottom: 8px;
letter-spacing: -0.02em;
}
.price-section__meta {
.market-header__copy p {
margin: 4px 0 0;
color: rgba(255, 255, 255, 0.88);
font-size: 0.75rem;
font-weight: 700;
}
.market-header__spacer {
width: 40px;
}
.market-body {
position: relative;
z-index: 1;
margin-top: -28px;
display: flex;
flex-direction: column;
gap: 12px;
padding: 0 14px;
}
.price-card {
position: relative;
padding: 14px 14px 10px;
border-radius: 18px;
background: #171c36;
border: 1px solid #3a446e;
}
.price-card::before {
content: '';
position: absolute;
inset: 0;
border-radius: inherit;
padding: 1.5px;
background: linear-gradient(
90deg,
transparent 0%,
rgba(240, 208, 120, 0.2) 14%,
#f6d98a 50%,
rgba(240, 208, 120, 0.2) 86%,
transparent 100%
);
-webkit-mask:
linear-gradient(#000 0 0) content-box,
linear-gradient(#000 0 0);
-webkit-mask-composite: xor;
mask:
linear-gradient(#000 0 0) content-box,
linear-gradient(#000 0 0);
mask-composite: exclude;
clip-path: inset(0 0 80% 0);
pointer-events: none;
}
.price-card__top {
display: grid;
grid-template-columns: 54px 1fr auto;
gap: 10px;
align-items: center;
justify-content: center;
gap: 24px;
direction: rtl;
margin-bottom: 8px;
}
.price-card__gold {
width: 54px;
height: 42px;
object-fit: contain;
}
.price-card__label {
margin: 0;
color: rgba(220, 228, 245, 0.82);
font-size: 0.75rem;
font-weight: 700;
}
.price-card__amount {
margin: 2px 0 0;
color: #fff;
font-size: 1.45rem;
font-weight: 800;
line-height: 1.2;
}
.price-card__unit {
margin: 0;
color: rgba(220, 228, 245, 0.7);
font-size: 0.75rem;
font-weight: 700;
}
.price-card__change {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 4px;
direction: ltr;
margin-bottom: 6px;
color: #2fce86;
font-size: 0.82rem;
font-weight: 800;
}
.price-section__unit {
font-size: 0.8125rem;
font-weight: 600;
color: var(--text-muted);
}
.price-section__change {
.price-card__change span {
display: inline-flex;
align-items: center;
gap: 4px;
font-size: 0.8125rem;
font-weight: 700;
color: #32d74b;
direction: rtl;
}
.price-card__change small {
color: rgba(220, 228, 245, 0.62);
font-size: 0.68rem;
font-weight: 600;
}
.price-card__change--down {
color: #ff6b6b;
}
.time-filters {
display: flex;
gap: 6px;
margin-top: 12px;
direction: rtl;
justify-content: space-between;
align-items: center;
margin-top: 4px;
}
.time-filter {
flex: 1;
min-height: 34px;
padding: 7px 4px;
border-radius: 12px;
font-size: 0.6875rem;
font-weight: 700;
background: rgba(255, 255, 255, 0.04);
color: var(--text-muted);
border: 1px solid rgba(255, 255, 255, 0.07);
transition: all var(--transition-fast);
flex: 0 0 auto;
height: 28px;
padding: 0 8px;
border: none;
border-radius: 8px;
background: transparent;
color: #9aa3c2;
font-family: inherit;
font-size: 0.75rem;
font-weight: 800;
}
.time-filter--active {
background: rgba(255, 255, 255, 0.08);
color: var(--text-main);
border-color: rgba(174, 185, 210, 0.35);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
background: linear-gradient(180deg, #f8d56a 0%, #e2aa2a 100%);
color: #2a2416;
padding: 0 12px;
}
/* ── Trade buttons ── */
.trade-buttons {
position: relative;
.trade-switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
direction: ltr;
margin-bottom: 22px;
direction: rtl;
}
.trade-buttons::after {
content: '';
position: absolute;
left: 50%;
bottom: -8px;
transform: translateX(-50%);
width: 110px;
height: 2px;
border-radius: 999px;
background: linear-gradient(
90deg,
transparent 0%,
rgba(241, 140, 22, 0.08) 12%,
rgba(241, 140, 22, 0.22) 28%,
rgba(241, 140, 22, 0.9) 50%,
rgba(241, 140, 22, 0.22) 72%,
rgba(241, 140, 22, 0.08) 88%,
transparent 100%
);
box-shadow: 0 0 8px rgba(241, 140, 22, 0.55);
pointer-events: none;
}
.trade-btn {
min-height: 52px;
border: none;
border-radius: 16px;
.trade-switch__btn {
height: 46px;
border-radius: 14px;
border: 1.5px solid #7c5cbf;
background: transparent;
color: #d9ccff;
font-family: inherit;
font-size: 1.0625rem;
font-size: 0.95rem;
font-weight: 800;
}
.trade-switch__btn--active {
border-color: transparent;
background: #7b46ef;
color: #fff;
cursor: pointer;
transition: transform var(--transition-fast), filter var(--transition-fast);
position: relative;
overflow: hidden;
}
.trade-btn::before {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(180deg, rgba(255, 255, 255, 0.16) 0%, transparent 48%);
pointer-events: none;
}
.trade-btn:active {
transform: scale(0.98);
}
.trade-btn--buy {
background: linear-gradient(180deg, #34d058 0%, #22b54b 52%, #138d36 100%);
}
.trade-btn--sell {
background: linear-gradient(180deg, #ff5060 0%, #e63443 52%, #b8172d 100%);
}
.trade-btn--modal {
width: 100%;
}
/* ── Asset card ── */
.asset-card {
.amount-card,
.estimate {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 118px;
padding: 16px 18px;
background: #1a223a;
border: 1px solid rgba(174, 185, 210, 0.28);
border-radius: 20px;
overflow: hidden;
}
.asset-card__info {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 4px;
direction: rtl;
text-align: right;
}
.asset-card__title {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 0.8125rem;
font-weight: 600;
color: var(--text-muted);
}
.asset-card__grams {
font-size: 1.625rem;
min-height: 58px;
padding: 0 14px;
border-radius: 16px;
background: #171c36;
border: 1px solid #3a446e;
color: #fff;
font-weight: 800;
color: var(--text-main);
line-height: 1.15;
}
.asset-card__unit {
font-size: 0.875rem;
font-weight: 600;
color: var(--text-muted);
margin-right: 4px;
}
.asset-card__value {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 0.875rem;
font-weight: 700;
color: var(--text-main);
}
.asset-card__coin {
width: 18px;
height: 18px;
object-fit: contain;
flex-shrink: 0;
}
.asset-card__value-unit {
font-size: 0.8125rem;
font-weight: 600;
color: var(--text-muted);
}
.asset-card__chest {
width: 88px;
height: 88px;
object-fit: contain;
flex-shrink: 0;
margin-left: -4px;
}
/* ── Trade modal form ── */
.trade-form {
.amount-card__stepper {
display: flex;
flex-direction: column;
gap: 10px;
align-items: center;
gap: 12px;
}
.trade-form__label {
font-size: 0.875rem;
font-weight: 700;
.amount-card__stepper button {
display: grid;
place-items: center;
width: 32px;
height: 32px;
border: none;
border-radius: 8px;
background: #2a2454;
color: #fff;
}
.trade-form__input {
padding: 12px 14px;
border-radius: var(--radius-sm);
border: 1px solid rgba(118, 75, 190, 0.45);
background: #040817;
color: var(--text-main);
.amount-card__stepper strong {
min-width: 36px;
text-align: center;
font-size: 1.05rem;
}
.estimate strong {
font-size: 1.25rem;
}
.trade-submit {
height: 52px;
border: none;
border-radius: 16px;
background: linear-gradient(180deg, #f8d56e 0%, #e7b02e 100%);
color: #1b2433;
font-family: inherit;
font-size: 1rem;
font-weight: 700;
appearance: textfield;
-moz-appearance: textfield;
}
.trade-form__input::-webkit-outer-spin-button,
.trade-form__input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
.trade-form__cost {
font-size: 1.0625rem;
font-size: 1.05rem;
font-weight: 800;
color: var(--gold-light);
}
.trade-form__hint {
font-size: 0.75rem;
color: var(--text-muted);
line-height: 1.5;
margin: 0;
.trade-submit:active {
transform: translateY(1px);
}
.trade-form__balance {
font-size: 0.8125rem;
color: var(--text-muted);
.trade-submit:disabled {
opacity: 0.7;
}
</style>