perf: optimize portfolio queries and workflows
This commit is contained in:
1 parent
da98d02661
commit
a7e0a0fe58
45 files changed
+4446
-637
No files matched your search
@@ -1,17 +1,22 @@
|
||||
import { t as tr } from './i18n';
|
||||
import { useState, type FormEvent } from 'react';
|
||||
import { nowMinute, money, requestUuid, type Position } from './api';
|
||||
export function TransferForm({
|
||||
accounts,
|
||||
busy,
|
||||
submit,
|
||||
initialSourceId,
|
||||
}: {
|
||||
accounts: Position[];
|
||||
busy: boolean;
|
||||
submit: (data: unknown) => void;
|
||||
initialSourceId?: string;
|
||||
}) {
|
||||
const [requestId] = useState(() => requestUuid());
|
||||
const [sourceId, setSource] = useState(accounts[0]?.id || ''),
|
||||
[targetId, setTarget] = useState(accounts[1]?.id || ''),
|
||||
const [sourceId, setSource] = useState(initialSourceId || accounts[0]?.id || ''),
|
||||
[targetId, setTarget] = useState(
|
||||
accounts.find((p) => p.id !== (initialSourceId || accounts[0]?.id))?.id || '',
|
||||
),
|
||||
[amount, setAmount] = useState('');
|
||||
const source = accounts.find((p) => p.id === sourceId),
|
||||
target = accounts.find((p) => p.id === targetId);
|
||||
@@ -21,15 +26,17 @@ export function TransferForm({
|
||||
submit(Object.fromEntries(new FormData(e.currentTarget)));
|
||||
}
|
||||
if (accounts.length < 2)
|
||||
return <p>请先创建至少两个启用中的资产账户。隐藏账户需验证密码后才能选择。</p>;
|
||||
return <p>{tr('请先创建至少两个启用中的资产账户。隐藏账户需验证密码后才能选择。')}</p>;
|
||||
return (
|
||||
<form onSubmit={save} className="transfer-form">
|
||||
<input type="hidden" name="requestId" value={requestId} />
|
||||
<p className="muted">
|
||||
双方余额同时更新。手续费从转出账户额外扣除;转账时间不能早于双方最新余额记录。
|
||||
{tr(
|
||||
'双方余额同时更新。正数手续费额外扣除,负数表示优惠抵扣(不超过转出金额);转账时间不能早于双方最新余额记录。',
|
||||
)}
|
||||
</p>
|
||||
<label>
|
||||
转出账户
|
||||
{tr('转出账户')}
|
||||
<select name="sourceId" value={sourceId} onChange={(e) => setSource(e.target.value)}>
|
||||
{accounts.map((p) => (
|
||||
<option key={p.id} value={p.id}>
|
||||
@@ -39,7 +46,7 @@ export function TransferForm({
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
转入账户
|
||||
{tr('转入账户')}
|
||||
<select name="targetId" value={targetId} onChange={(e) => setTarget(e.target.value)}>
|
||||
{accounts.map((p) => (
|
||||
<option key={p.id} value={p.id} disabled={p.id === sourceId}>
|
||||
@@ -50,7 +57,8 @@ export function TransferForm({
|
||||
</label>
|
||||
<div className="form-columns">
|
||||
<label>
|
||||
转出金额({source?.currency})
|
||||
{tr('转出金额(')}
|
||||
{source?.currency})
|
||||
<input
|
||||
name="amount"
|
||||
required
|
||||
@@ -61,7 +69,8 @@ export function TransferForm({
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
实际到账({target?.currency})
|
||||
{tr('实际到账(')}
|
||||
{target?.currency})
|
||||
{same ? (
|
||||
<input name="received" required readOnly value={amount} />
|
||||
) : (
|
||||
@@ -76,20 +85,24 @@ export function TransferForm({
|
||||
</label>
|
||||
</div>
|
||||
{!same && (
|
||||
<p className="notice warning">跨币种请填写银行实际到账金额;本次转账不修改公共参考汇率。</p>
|
||||
<p className="notice warning">
|
||||
{tr('跨币种请填写银行实际到账金额;本次转账不修改公共参考汇率。')}
|
||||
</p>
|
||||
)}
|
||||
<label>
|
||||
额外手续费({source?.currency})
|
||||
{tr('手续费 / 优惠(')}
|
||||
{source?.currency}
|
||||
{tr(',优惠填负数)')}
|
||||
<input
|
||||
name="fee"
|
||||
required
|
||||
defaultValue="0"
|
||||
inputMode="decimal"
|
||||
pattern="(0|[1-9][0-9]{0,15})(\.[0-9]{1,8})?"
|
||||
pattern="-?(0|[1-9][0-9]{0,15})(\.[0-9]{1,8})?"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
转账时间(北京时间)
|
||||
{tr('转账时间(北京时间)')}
|
||||
<input
|
||||
name="date"
|
||||
type="datetime-local"
|
||||
@@ -99,11 +112,11 @@ export function TransferForm({
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
备注
|
||||
{tr('备注')}
|
||||
<textarea className="note-input" name="notes" maxLength={2000} rows={2} />
|
||||
</label>
|
||||
<button className="primary" disabled={busy || sourceId === targetId}>
|
||||
{busy ? '正在转账…' : '确认转账'}
|
||||
{busy ? tr('正在转账…') : tr('确认转账')}
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user