mdi-minus
@@ -1446,7 +1450,7 @@ const activeTab = ref('buy')
const limitType = ref('Limit')
const expirationEnabled = ref(false)
const selectedOption = ref<'yes' | 'no'>(props.initialOption ?? 'no')
-const limitPrice = ref(0.82) // 初始限价,单位:美元
+const limitPrice = ref(0.82) // 内部存储 0–1,显示为美分与按钮一致
const shares = ref(20) // 初始份额(正整数)
const expirationTime = ref('5m') // 初始过期时间
const EXPIRATION_VALUES = ['5m', '15m', '30m', '1h', '2h', '4h', '8h', '12h', '1d', '2d', '3d'] as const
@@ -1485,6 +1489,8 @@ const emit = defineEmits<{
}>()
// Computed properties
+/** Limit Price 显示值(美分),与 Yes/No 按钮单位一致 */
+const limitPriceCentsDisplay = computed(() => Math.round(limitPrice.value * 10000) / 100)
const currentPrice = computed(() => {
return `${(limitPrice.value * 100).toFixed(0)}¢`
})
@@ -1571,11 +1577,11 @@ const handleOptionChange = (option: 'yes' | 'no') => {
emit('optionChange', option)
}
-/** 仅接受 135 个允许档位:输入值吸附到最近档位,非法值忽略 */
+/** 输入为美分(0–100),与 Yes/No 按钮单位一致 */
function onLimitPriceInput(v: unknown) {
const num = v == null ? NaN : Number(v)
- if (!Number.isFinite(num) || num < 0 || num > 1) return
- limitPrice.value = snapToAllowedPrice(num)
+ if (!Number.isFinite(num) || num < 0 || num > 100) return
+ limitPrice.value = snapToAllowedPrice(num / 100)
}
/** 失焦时吸附到允许档位 */
@@ -1583,7 +1589,7 @@ function onLimitPriceBlur() {
limitPrice.value = snapToAllowedPrice(limitPrice.value)
}
-/** 只允许数字和小数点输入 */
+/** 只允许数字和小数点输入(美分 0–100) */
function onLimitPriceKeydown(e: KeyboardEvent) {
const key = e.key
const allowed = ['Backspace', 'Delete', 'Tab', 'ArrowLeft', 'ArrowRight', 'Home', 'End']
@@ -1596,11 +1602,11 @@ function onLimitPriceKeydown(e: KeyboardEvent) {
e.preventDefault()
}
-/** 粘贴时只接受有效数字 */
+/** 粘贴时只接受有效美分数(0–100) */
function onLimitPricePaste(e: ClipboardEvent) {
const text = e.clipboardData?.getData('text') ?? ''
const num = parseFloat(text)
- if (!Number.isFinite(num) || num < 0 || num > 1) {
+ if (!Number.isFinite(num) || num < 0 || num > 100) {
e.preventDefault()
}
}
diff --git a/src/views/Home.vue b/src/views/Home.vue
index a83eff0..8b4fb64 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -165,6 +165,8 @@
:is-new="card.isNew"
:market-id="card.marketId"
:clob-token-ids="card.clobTokenIds"
+ :yes-price="card.yesPrice"
+ :no-price="card.noPrice"
@open-trade="onCardOpenTrade"
/>
@@ -514,12 +516,23 @@ const tradeDialogMarket = ref<{
clobTokenIds?: string[]
yesLabel?: string
noLabel?: string
+ yesPrice?: number
+ noPrice?: number
} | null>(null)
const scrollRef = ref(null)
function onCardOpenTrade(
side: 'yes' | 'no',
- market?: { id: string; title: string; marketId?: string; yesLabel?: string; noLabel?: string },
+ market?: {
+ id: string
+ title: string
+ marketId?: string
+ yesLabel?: string
+ noLabel?: string
+ yesPrice?: number
+ noPrice?: number
+ clobTokenIds?: string[]
+ },
) {
tradeDialogSide.value = side
tradeDialogMarket.value = market ?? null
@@ -537,9 +550,14 @@ const homeTradeMarketPayload = computed(() => {
const m = tradeDialogMarket.value
if (!m) return undefined
const marketId = m.marketId ?? m.id
- const chance = 50
- const yesPrice = Math.min(1, Math.max(0, chance / 100))
- const noPrice = 1 - yesPrice
+ const yesPrice =
+ m.yesPrice != null && Number.isFinite(m.yesPrice)
+ ? Math.min(1, Math.max(0, m.yesPrice))
+ : 0.5
+ const noPrice =
+ m.noPrice != null && Number.isFinite(m.noPrice)
+ ? Math.min(1, Math.max(0, m.noPrice))
+ : 1 - yesPrice
const outcomes =
m.yesLabel != null || m.noLabel != null
? [m.yesLabel ?? 'Yes', m.noLabel ?? 'No']