-
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.
Chore: rebrand nodeauthrequired popop (#1942)
* chore: type fix * chore: rebrand NodeAuthRequiredPopup * chore: extract NodeAuthTab for reus * feat: use Node Authentication tab if required * chore: show default network
- Loading branch information
Showing
9 changed files
with
112 additions
and
72 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
58 changes: 31 additions & 27 deletions
58
packages/desktop/components/popup/popups/NodeAuthRequiredPopup.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,54 +1,58 @@ | ||
<script lang="ts"> | ||
import { Text, TextInput, TextType } from '@ui' | ||
import { NodeAuthTab } from '@ui' | ||
import type { IAuth } from '@iota/sdk' | ||
import { handleError } from '@core/error/handlers' | ||
import { localize } from '@core/i18n' | ||
import { closePopup } from '@desktop/auxiliary/popup' | ||
import { Button } from '@bloomwalletio/ui' | ||
import PopupTemplate from '../PopupTemplate.svelte' | ||
import { IError } from '@core/error' | ||
export let onSubmit: (auth: IAuth) => unknown = () => {} | ||
let isBusy = false | ||
let auth: IAuth | ||
let jwtError: string | undefined | ||
let jwt: string | ||
let jwtError: string | ||
$: disabled = isBusy || !auth | ||
$: disabled = !jwt || isBusy | ||
async function handleSubmit(): Promise<void> { | ||
async function onConfirmClick(): Promise<void> { | ||
try { | ||
isBusy = true | ||
const auth = { jwt } | ||
await onSubmit(auth) | ||
isBusy = false | ||
} catch (err) { | ||
const error = err as IError | ||
isBusy = false | ||
const authenticationError = err?.error?.match(/(jwt)/g)?.[0] | ||
const authenticationError = error?.error?.match(/(jwt)/g)?.[0] | ||
switch (authenticationError) { | ||
case 'jwt': | ||
jwtError = err.error | ||
jwtError = error?.error | ||
break | ||
default: | ||
handleError(err) | ||
handleError(error) | ||
break | ||
} | ||
} | ||
} | ||
function onCancelClick(): void { | ||
closePopup() | ||
} | ||
</script> | ||
|
||
<form id="node-auth-required" on:submit|preventDefault={handleSubmit}> | ||
<Text type={TextType.h3} classes="mb-6">{localize('popups.nodeAuthRequired.title')}</Text> | ||
<Text fontSize="15">{localize('popups.nodeAuthRequired.body')}</Text> | ||
<div class="flex flex-col w-full space-y-5 mt-4"> | ||
<TextInput | ||
bind:value={jwt} | ||
bind:error={jwtError} | ||
placeholder={localize('general.jwt')} | ||
label={localize('general.jwt')} | ||
/> | ||
</div> | ||
<div class="flex w-full space-x-4 mt-6"> | ||
<Button variant="outlined" width="full" on:click={() => closePopup()} text={localize('actions.cancel')} /> | ||
<Button {disabled} busy={isBusy} type="submit" width="full" text={localize('actions.confirm')} /> | ||
</div> | ||
</form> | ||
<PopupTemplate | ||
title={localize('popups.nodeAuthRequired.title')} | ||
description={localize('popups.nodeAuthRequired.body')} | ||
backButton={{ | ||
text: localize('actions.cancel'), | ||
onClick: onCancelClick, | ||
}} | ||
continueButton={{ | ||
text: localize('actions.confirm'), | ||
onClick: onConfirmClick, | ||
disabled, | ||
}} | ||
busy={isBusy} | ||
> | ||
<NodeAuthTab bind:auth {jwtError} /> | ||
</PopupTemplate> |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { localize } from '@core/i18n' | ||
import { KeyValue } from '../types' | ||
import { Tab } from '@ui/enums' | ||
import { PopupTab } from '@ui/enums' | ||
|
||
export function getTabItems(items: Tab[]): KeyValue<string>[] { | ||
export function getTabItems(items: PopupTab[]): KeyValue<string>[] { | ||
return items.map((item) => ({ key: item, value: localize(`general.${item}`) })) | ||
} |
46 changes: 46 additions & 0 deletions
46
packages/shared/src/components/molecules/NodeAuthTab.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,46 @@ | ||
<script lang="ts"> | ||
import { KeyValue } from '@ui' | ||
import { localize } from '@core/i18n' | ||
import { PasswordInput, TextInput, Tabs } from '@bloomwalletio/ui' | ||
import { IAuth } from '@iota/sdk' | ||
export let auth: IAuth | undefined | ||
export let jwtError: string | undefined = undefined | ||
let [username, password] = auth?.basicAuthNamePwd ?? ['', ''] | ||
let jwt = auth?.jwt ?? '' | ||
enum Auth { | ||
Credentials = 'credentials', | ||
Jwt = 'jwt', | ||
} | ||
const tabs: KeyValue<string>[] = [ | ||
{ key: Auth.Credentials, value: localize('popups.node.credentials') }, | ||
{ key: Auth.Jwt, value: localize('popups.node.jwt') }, | ||
] | ||
let selectedTab = tabs[0] | ||
$: isJwtAuthentication = selectedTab.key === Auth.Jwt | ||
$: selectedTab, jwt, username, password, setAuth() | ||
function setAuth(): void { | ||
if (isJwtAuthentication && jwt) { | ||
auth = { jwt } | ||
} else if (!isJwtAuthentication && username && password) { | ||
auth = { basicAuthNamePwd: [username, password] as [string, string] } | ||
} else { | ||
auth = undefined | ||
} | ||
} | ||
</script> | ||
|
||
<div class="flex flex-col w-full space-y-4"> | ||
<Tabs bind:selectedTab {tabs} /> | ||
{#if isJwtAuthentication} | ||
<TextInput bind:value={jwt} error={jwtError} label={localize('popups.node.jwt')} /> | ||
{:else} | ||
<TextInput bind:value={username} label={localize('general.username')} /> | ||
<PasswordInput bind:value={password} minlength={1} label={localize('general.password')} /> | ||
{/if} | ||
</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
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
File renamed without changes.
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