/
NodeInput.svelte
52 lines (46 loc) · 1.46 KB
/
NodeInput.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<script lang="ts">
import { SelectorInput, IOption, Modal } from 'shared/components'
import { localize } from '@core/i18n'
import { activeProfile } from '@core/profile/stores'
import { isValidUrl } from '@core/utils'
export let disabled = false
export let error: string
export let nodeUrl: string
let inputElement: HTMLInputElement
let modal: Modal
let nodeOptions: IOption[]
let selected: IOption
$: clientOptionsNodes = $activeProfile?.clientOptions?.nodes
$: clientOptionsNodes, (nodeOptions = getNodeOptionsFromClientOptions())
$: nodeUrl = selected?.value
export async function validate(): Promise<void> {
try {
if (!isValidUrl(selected?.value)) {
throw new Error(localize('error.node.invalid'))
}
return Promise.resolve()
} catch (err) {
error = err?.message ?? err
return Promise.reject(error)
}
}
function getNodeOptionsFromClientOptions(): IOption[] {
return clientOptionsNodes
.filter((node) => !node.disabled)
.map((node, index) => ({
id: index,
key: null,
value: node.url,
}))
}
</script>
<SelectorInput
labelLocale="views.governance.details.proposalInformation.nodeUrl"
bind:selected
bind:inputElement
bind:modal
bind:error
{disabled}
options={nodeOptions}
{...$$restProps}
/>