Skip to content

Commit

Permalink
new: prevent user to create 2 comchain account with 2 fast button click
Browse files Browse the repository at this point in the history
  • Loading branch information
vaab committed Sep 17, 2024
1 parent af960d3 commit bba9c6d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/components/CreateAccount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
import AuthPref from "@/components/AuthPref.vue"
import PasswordField from "@/components/PasswordField.vue"
import { mapGetters } from "vuex"
import { debounceMethod } from "@/utils/debounce"
@Options({
name: "CreateAccount",
components: { AuthPref, PasswordField },
Expand Down Expand Up @@ -255,7 +256,7 @@
saveSimplifiedAuthPref(accountAuthService: any, userConfigInput: any) {
this.userAuthPref = [accountAuthService, userConfigInput]
},
async createUserAccount() {
createUserAccount: debounceMethod(async function () {
let userAccount
try {
userAccount = await this.$store.dispatch("createUserAccount", [
Expand Down Expand Up @@ -299,7 +300,7 @@
}
this.$store.dispatch("fetchComponentDefs")
this.$router.push({ name: "dashboard" })
},
}),
},
})
export default class CreateAccount extends Vue {}
Expand Down
10 changes: 5 additions & 5 deletions src/i18n/fr-FR/app.po
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ msgstr "Le mot de passe doit contenir au moins un caractère spécial"
msgid "Password should use at least one uppercase character"
msgstr "Le mot de passe doit contenir au moins une lettre majuscule"

#: src/components/CreateAccount.vue:247
#: src/components/CreateAccount.vue:248
msgid "Passwords do not match"
msgstr "Le mot de passe entré n'est pas identique"

Expand Down Expand Up @@ -688,7 +688,7 @@ msgstr ""
msgid "Please scan the QR code above to proceed"
msgstr "Veuillez scanner le QR code ci-dessus pour continuer"

#: src/components/CreateAccount.vue:274
#: src/components/CreateAccount.vue:275
#: src/components/TheBankAccountList.vue:245 src/services/lokapiService.ts:229
msgid "Please try again or contact your administrator"
msgstr "Veuillez ré-éssayer ou contacter votre administrateur"
Expand Down Expand Up @@ -822,7 +822,7 @@ msgstr "%{amount} envoyé"
msgid "Settings"
msgstr "Préferences"

#: src/components/CreateAccount.vue:293
#: src/components/CreateAccount.vue:294
msgid ""
"Settings for simplified authentication were not saved correctly... Please "
"try again in the \"Settings\" page or contact your administrator"
Expand Down Expand Up @@ -1153,11 +1153,11 @@ msgstr ""
msgid "User or email already exist."
msgstr "Utilisateur ou e-mail existe déjà."

#: src/components/CreateAccount.vue:279
#: src/components/CreateAccount.vue:280
msgid "Wallet already created"
msgstr "Compte déjà créé"

#: src/components/CreateAccount.vue:272
#: src/components/CreateAccount.vue:273
msgid "Wallet creation unexpectedly failed."
msgstr "Création de compte interrompue inopinément."

Expand Down
37 changes: 37 additions & 0 deletions src/utils/debounce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export function debounceMethod<
T extends (this: any, ...args: any[]) => Promise<any>
>(fn: T): T {
const promiseMapKey = Symbol("__debouncePromiseMap__")

return function (this: any, ...args: Parameters<T>): ReturnType<T> {
if (!this[promiseMapKey]) {
this[promiseMapKey] = new Map<string, ReturnType<T>>()
}

const argsKey = JSON.stringify(args)

if (!this[promiseMapKey].has(argsKey)) {
const promise = (async () => {
try {
return await fn.apply(this, args)
} finally {
this[promiseMapKey].delete(argsKey)
}
})()

this[promiseMapKey].set(argsKey, promise)
} else {
console.trace(`Debounced call`)
}

return this[promiseMapKey].get(argsKey)
} as unknown as T
}

export function debounce(
target: any,
propertyKey: string,
descriptor: PropertyDescriptor
) {
return debounceMethod(descriptor.value)
}

0 comments on commit bba9c6d

Please sign in to comment.