-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 2024-12-18-dotrain-yaml-order
- Loading branch information
Showing
14 changed files
with
183 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
packages/ui-components/src/__tests__/CodeMirrorRainlang.test.svelte
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { render, fireEvent } from '@testing-library/svelte'; | ||
import InputToken from '../lib/components/input/InputToken.svelte'; | ||
|
||
describe('InputToken', () => { | ||
it('renders with initial values', () => { | ||
const address = '0xc0D477556c25C9d67E1f57245C7453DA776B51cf'; | ||
const decimals = 10; | ||
const { getByTestId } = render(InputToken, { props: { address, decimals } }); | ||
|
||
const input = getByTestId('token-address').querySelector('input'); | ||
expect(input?.value).toBe('0xc0D477556c25C9d67E1f57245C7453DA776B51cf'); | ||
const decimalsInput = getByTestId('token-decimals-input').querySelector('input'); | ||
expect(decimalsInput?.value).toBe('10'); | ||
}); | ||
|
||
it('shows error for invalid address', async () => { | ||
const address = 'abc'; | ||
const decimals = 0; | ||
const { getByTestId, getByText } = render(InputToken, { props: { address, decimals } }); | ||
|
||
const addressInput = getByTestId('token-address').querySelector('input') as HTMLInputElement; | ||
await fireEvent.input(addressInput, { target: { value: 'invalidAddress' } }); | ||
|
||
expect(getByText('Invalid Address')).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not show error for valid address', async () => { | ||
const address = ''; | ||
const decimals = 0; | ||
const { getByTestId, queryByText } = render(InputToken, { props: { address, decimals } }); | ||
|
||
const addressInput = getByTestId('token-address').querySelector('input') as HTMLInputElement; | ||
await fireEvent.input(addressInput, { | ||
target: { value: '0xc0D477556c25C9d67E1f57245C7453DA776B51cf' } | ||
}); | ||
|
||
expect(queryByText('Invalid Address')).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
declare namespace svelteHTML { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
interface HTMLAttributes<T> { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
'on:complete'?: (event: any) => any; | ||
} | ||
} |
34 changes: 29 additions & 5 deletions
34
packages/ui-components/src/lib/components/CodeMirrorRainlang.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,38 @@ | ||
<script lang="ts"> | ||
import type { Order } from '@rainlanguage/orderbook/js_api'; | ||
import { extendOrder } from '@rainlanguage/orderbook/js_api'; | ||
import CodeMirror from 'svelte-codemirror-editor'; | ||
import { RainlangLR } from 'codemirror-rainlang'; | ||
export let order: Order | undefined = undefined; | ||
export let rainlangText: string = ''; | ||
export let rainlangText: string | undefined = undefined; | ||
export let codeMirrorTheme; | ||
export let disabled = false; | ||
export let styles = {}; | ||
export let codeMirrorDisabled = true; | ||
export let codeMirrorStyles = {}; | ||
$: value = order ? extendOrder(order).rainlang : rainlangText; | ||
$: extendedOrder = order ? extendOrder(order) : undefined; | ||
</script> | ||
|
||
<slot name="codemirror" {value} {codeMirrorTheme} {disabled} {styles}></slot> | ||
{#if extendedOrder?.rainlang} | ||
<CodeMirror | ||
value={rainlangText || extendedOrder.rainlang} | ||
extensions={[RainlangLR]} | ||
theme={codeMirrorTheme} | ||
readonly={codeMirrorDisabled} | ||
useTab={true} | ||
tabSize={2} | ||
styles={{ | ||
'&': { | ||
width: '100%' | ||
}, | ||
...codeMirrorStyles | ||
}} | ||
/> | ||
{:else if !extendedOrder?.rainlang && !rainlangText} | ||
<div | ||
class="w-full tracking-tight text-gray-900 dark:text-white" | ||
data-testid="rainlang-not-included" | ||
> | ||
Rain source not included in order meta | ||
</div> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/ui-components/src/lib/components/input/InputToken.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<script lang="ts"> | ||
import { Helper, Input } from 'flowbite-svelte'; | ||
import type { InputMask } from 'imask'; | ||
import { imask } from '@imask/svelte'; | ||
import { isAddress } from 'viem'; | ||
let decimalsRaw: string = ''; | ||
export let decimals: number | undefined; | ||
export let address: string = ''; | ||
$: isAddressValid = address && address.length > 0 && isAddress(address); | ||
$: { | ||
if (decimals !== undefined) { | ||
decimalsRaw = decimals.toString(); | ||
} | ||
} | ||
const decimalsMaskOptions = { | ||
mask: Number, | ||
min: 0, | ||
lazy: false, | ||
scale: 0, | ||
thousandsSeparator: '', | ||
radix: '.' | ||
}; | ||
function decimalsComplete({ detail }: { detail: InputMask }) { | ||
decimalsRaw = detail.value; | ||
if (detail.unmaskedValue.length === 0) { | ||
decimals = 0; | ||
} else { | ||
decimals = parseInt(detail.unmaskedValue); | ||
} | ||
} | ||
</script> | ||
|
||
<div class="flex w-full items-start justify-start space-x-2"> | ||
<div class="grow" data-testid="token-address"> | ||
<div class="relative flex"> | ||
<Input label="Token Address" name="address" required bind:value={address} /> | ||
</div> | ||
|
||
{#if !isAddressValid && address.length > 0} | ||
<Helper class="mt-2 text-sm" color="red">Invalid Address</Helper> | ||
{/if} | ||
|
||
<Helper class="mt-2 text-sm">Token Address</Helper> | ||
</div> | ||
<div class="w-32 grow-0 break-all" data-testid="token-decimals-input"> | ||
<input | ||
type="text" | ||
value={decimalsRaw} | ||
class="focus:border-primary-500 focus:ring-primary-500 dark:focus:border-primary-500 dark:focus:ring-primary-500 block w-full rounded-lg border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 disabled:cursor-not-allowed disabled:opacity-50 rtl:text-right dark:border-gray-500 dark:bg-gray-600 dark:text-white dark:placeholder-gray-400" | ||
use:imask={decimalsMaskOptions} | ||
on:complete={decimalsComplete} | ||
/> | ||
<Helper class="break-word mt-2 text-sm">Decimals</Helper> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.