Skip to content

Commit ac4703b

Browse files
committed
Trading Offers Create
1 parent 2929a4a commit ac4703b

3 files changed

Lines changed: 33 additions & 25 deletions

File tree

src/lib/components/CurrentBankPicker.svelte

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@
1111
action?: string;
1212
/** Called with the new bank id whenever the selection changes. */
1313
onSelect?: (bankId: string) => void;
14+
/** Render inline with no help text, for placing in a header row. */
15+
compact?: boolean;
1416
}
1517
16-
let { banks, selectedBankId = '', action = '?/setBank', onSelect }: Props = $props();
18+
let {
19+
banks,
20+
selectedBankId = '',
21+
action = '?/setBank',
22+
onSelect,
23+
compact = false
24+
}: Props = $props();
1725
1826
let saving = $state(false);
1927
let justSaved = $state(false);
@@ -42,15 +50,15 @@
4250
};
4351
}}
4452
>
45-
<label class="label">
46-
<span class="label-text flex items-center gap-2">
53+
<label class="label" class:flex={compact} class:items-center={compact} class:gap-2={compact}>
54+
<span class="label-text flex items-center gap-2 whitespace-nowrap">
4755
<Landmark class="size-4 text-primary-500" />
4856
Current Bank
4957
</span>
5058
<div class="flex items-center gap-3">
5159
<select
5260
name="bank_id"
53-
class="select"
61+
class="select max-w-md"
5462
value={selectedBankId}
5563
disabled={saving}
5664
onchange={(e) => {
@@ -77,8 +85,10 @@
7785
{/if}
7886
</div>
7987
</label>
80-
<p class="text-xs text-surface-600-400 mt-1">
81-
Saved to your OBP profile (<span class="font-mono">CURRENT_BANK_ID</span>) and shared across OBP
82-
apps.
83-
</p>
88+
{#if !compact}
89+
<p class="text-xs text-surface-600-400 mt-1">
90+
Saved to your OBP profile (<span class="font-mono">CURRENT_BANK_ID</span>) and shared across
91+
OBP apps.
92+
</p>
93+
{/if}
8494
</form>

src/routes/trading/+page.svelte

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,19 @@
4949
</script>
5050

5151
<div class="p-8">
52-
<div class="flex items-center gap-4 mb-8">
52+
<div class="flex flex-wrap items-center gap-4 mb-8">
5353
<TrendingUp class="size-8 text-primary-500" />
5454
<h1 class="h1">Trading</h1>
55+
{#if data.isAuthenticated}
56+
<div class="ms-auto">
57+
<CurrentBankPicker
58+
banks={data.banks}
59+
selectedBankId={bankId}
60+
onSelect={(b) => (bankId = b)}
61+
compact
62+
/>
63+
</div>
64+
{/if}
5565
</div>
5666

5767
{#if !data.isAuthenticated}
@@ -63,19 +73,6 @@
6373
</div>
6474
{:else}
6575
<div class="space-y-8">
66-
<section class="card p-8 preset-filled-surface-100-900">
67-
<h2 class="h3 mb-2">Current Bank</h2>
68-
<p class="text-surface-600-400 mb-6">
69-
Pick the bank you're trading on. This is saved to your OBP profile and used as the default
70-
below.
71-
</p>
72-
<CurrentBankPicker
73-
banks={data.banks}
74-
selectedBankId={bankId}
75-
onSelect={(b) => (bankId = b)}
76-
/>
77-
</section>
78-
7976
<section class="card p-8 preset-filled-surface-100-900">
8077
<div class="flex flex-wrap items-center justify-between gap-4 mb-2">
8178
<h2 class="h3">Your Accounts</h2>

src/routes/trading/banks/[bankId]/accounts/[accountId]/views/[viewId]/offers/create/+page.server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,17 @@ export const actions: Actions = {
5858
minimum_fill: (formData.get('minimum_fill') as string) ?? ''
5959
};
6060

61+
// The API expects amounts as decimal strings (e.g. "100.00"), not numbers.
6162
const body: Record<string, unknown> = {
6263
offer_type: values.offer_type,
6364
asset_code: values.asset_code,
64-
asset_amount: values.asset_amount ? Number(values.asset_amount) : undefined,
65+
asset_amount: values.asset_amount || undefined,
6566
price_currency: values.price_currency,
66-
price_amount: values.price_amount ? Number(values.price_amount) : undefined,
67+
price_amount: values.price_amount || undefined,
6768
settlement_account_id: values.settlement_account_id
6869
};
6970
if (values.expiry_datetime) body.expiry_datetime = values.expiry_datetime;
70-
if (values.minimum_fill) body.minimum_fill = Number(values.minimum_fill);
71+
if (values.minimum_fill) body.minimum_fill = values.minimum_fill;
7172

7273
for (const key of Object.keys(body)) {
7374
if (body[key] === '' || body[key] === null || body[key] === undefined) {

0 commit comments

Comments
 (0)