Skip to content

Commit

Permalink
chore: add normal form
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaZhem committed Aug 15, 2024
1 parent 1dd4ff7 commit cb02d57
Showing 1 changed file with 12 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import {
Output,
} from '@angular/core';
import {
FormArray,
FormControl,
FormGroup,
FormsModule,
ReactiveFormsModule,
Validators,
} from '@angular/forms';
import {TuiAutoFocus, tuiMarkControlAsTouchedAndValidate} from '@taiga-ui/cdk';
import {TuiAlertService, TuiButton, TuiDialog, TuiError, TuiHint} from '@taiga-ui/core';
import {TuiButton, TuiDialog, TuiError, TuiHint} from '@taiga-ui/core';
import {
TUI_VALIDATION_ERRORS,
TuiAvatar,
Expand All @@ -28,13 +27,6 @@ import {of} from 'rxjs';

import type {TokenMinter} from '../minter.component';

interface MinterData {
readonly title: string;
readonly defaultValue: string;
readonly type: string;
readonly description: string;
}

@Component({
standalone: true,
selector: 'lmb-minter-deploy',
Expand Down Expand Up @@ -81,45 +73,9 @@ export class MinterDeployComponent {
description: new FormControl(''),
});

protected readonly minterData: MinterData[] = [
{
title: 'Jetton Name',
defaultValue: '',
type: 'text',
description: 'Your project name with spaces',
},
{
title: 'Jetton Symbol',
defaultValue: '',
type: 'text',
description:
'Currency symbol appearing in balance (usually 3-5 uppercase chars)',
},
{
title: 'Number of tokens',
defaultValue: '0',
type: 'number',
description:
'Number of initial tokens to mint and send to your waller address',
},
{
title: 'Description',
defaultValue: '',
type: 'text',
description: 'Optional sentence explaining about yor project',
},
];

protected readonly push = inject(TuiPushService);
protected readonly alert = inject(TuiAlertService);
protected minterForm = new FormArray(
this.minterData.map((item) => new FormControl(item.defaultValue)),
);

protected openIcon = false;
protected warningIcon = false;
protected success = false;
protected urlIcon = '';

@Output()
public readonly tokenChange = new EventEmitter<TokenMinter>();
Expand All @@ -130,46 +86,20 @@ export class MinterDeployComponent {

protected onSubmit(): void {
tuiMarkControlAsTouchedAndValidate(this.form);
}

protected deploy(): void {
let required = true;

for (let i = 0; i < this.minterForm.length; i++) {
if (this.minterData[i].defaultValue === this.minterForm.controls[i].value) {
required = false;
}
}

if (!required) {
this.alert
.open('Тot all required fields are filled in', {
label: 'Try again',
status: 'warning',
if (this.form.valid) {
this.push
.open('Minted your token', {
heading: 'Success',
icon: 'check',
})
.subscribe();

return;
this.tokenChange.emit({
urlIcon: this.form.controls.urlIcon.value ?? '',
token: this.form.controls.name.value ?? '',
symbol: this.form.controls.symbol.value ?? '',
amount: Number(this.form.controls.amount.value) ?? 0,
});
}

if (this.urlIcon === '') {
this.warningIcon = true;

return;
}

this.push
.open('Minted your token', {
heading: 'Success',
icon: 'check',
})
.subscribe();
this.success = true;
this.tokenChange.emit({
urlIcon: this.urlIcon,
token: this.minterForm.controls[0].value ?? '',
symbol: this.minterForm.controls[1].value ?? '',
amount: Number(this.minterForm.controls[2].value) ?? 0,
});
}
}

0 comments on commit cb02d57

Please sign in to comment.