'Ionic AlertMessage Double Async Requests

My application have an AllertMessage pattern, so it's a very delicate component. The issue is that from time to time It makes double requests, and I think there's got to do something all of the async functions.

async create(message?: string) {
    const options: {} = {
        header: 'Informe a pulseira de acesso.',
        subHeader: message,
        backdropDismiss: false,
        cssClass: 'alert-bracelet',
        mode: 'ios',
        inputs: [
          {
            name: 'bracelet',
            type: 'password',
            placeholder: 'Código da pulseira',
            cssClass: 'bold font-size'
          }
        ],
        buttons: [
          {
            text: 'Cancelar',
            cssClass: 'btn-cancel bold font-size',
            handler: () => {
                this.observableUtilService.sendMessageBracelet(false);
                this.alertController.dismiss();
            }
          }, {
            text: 'Confirmar',
            cssClass: 'btn-confirm bold font-size',
            handler: async (data) => {
                this.confirmBracelet(data.bracelet).then(
                    (d2) => this.observableUtilService.sendMessageBracelet(d2.user),
                    (error) => this.observableUtilService.sendMessageBracelet(false));
                this.alertController.dismiss();
            }
          }
        ]
      };
      const alert = await this.alertController.create(options);
      return await alert.present().then(() => this.customAlertBracelet());
}


private async confirmBracelet(bracelet: string): Promise<any> {
        const myPromisse = new Promise((resolve, reject) => {
            this.userService.bracelet(bracelet).subscribe((data) => resolve({user: data, success: true}),
              async () => {
                const toast = await this.easyMarineToast.create('Pulseira inválida', 'danger');
                toast.present();
                reject(false);
            });
        });
        return myPromisse;
    }

It basically receives a code (ID) and checks in an api, and if it is true than the service that called the AllertMessage will fullfill the request.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source