Skip to content

Commit

Permalink
fix: response handling from api account check, notifications for succ…
Browse files Browse the repository at this point in the history
…essful account creation
  • Loading branch information
donnyquixotic committed Mar 15, 2024
1 parent c0594d8 commit 44a8f55
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions src/pages/testnet/DevelopersPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const $q = useQuasar();
const route = useRoute();
const router = useRouter();
const TRANSACTION_RESPONSE_LENGTH = 64;
// proxy functions for vuex actions
function faucet(send_to: string) {
return store.dispatch('testnet/faucet', send_to);
Expand Down Expand Up @@ -50,19 +52,22 @@ const tlosEvmLabel = computed(() => {
// Result Notifications
async function handleAnswer(answer: string | object, successMessage: string) {
if (typeof answer === 'string') {
if (
typeof answer === 'object' ||
answer.length === TRANSACTION_RESPONSE_LENGTH
) {
Notify.create({
message: answer,
message: successMessage,
position: 'top',
color: 'negative',
color: 'primary',
textColor: 'white',
actions: [{ label: 'Dismiss', color: 'white' }],
});
} else if (typeof answer === 'object') {
} else if (typeof answer === 'string') {
Notify.create({
message: successMessage,
message: answer,
position: 'top',
color: 'primary',
color: 'negative',
textColor: 'white',
actions: [{ label: 'Dismiss', color: 'white' }],
});
Expand Down Expand Up @@ -92,13 +97,18 @@ function checkAccountAvailability(account_name: string) {
}
return getAccount(account_name)
.then(() => {
createAccountForm.value.available = false;
return 'Account already exists';
.then((response) => {
if (response.status === 200) {
// 200 indicates account is available
createAccountForm.value.available = true;
return true;
} else {
createAccountForm.value.available = false;
return 'Account already exists';
}
})
.catch(() => {
createAccountForm.value.available = true;
return true;
.catch((e) => {
console.log(e);
})
.finally(() => {
createAccountForm.value.checking_account = false;
Expand Down Expand Up @@ -139,13 +149,18 @@ const sendTlosForm = ref({
function checkAccountExists(account: string) {
return getAccount(account)
.then(() => {
sendTlosForm.value.account_exists = true;
return true;
.then((response) => {
if (response.status === 200) {
// 200 indicates account is available
sendTlosForm.value.account_exists = false;
return 'Account does not exist';
} else {
sendTlosForm.value.account_exists = true;
return true;
}
})
.catch(() => {
sendTlosForm.value.account_exists = false;
return 'Account does not exist';
.catch((e) => {
console.log(e);
})
.finally(() => {
sendTlosForm.value.checking_account = false;
Expand Down Expand Up @@ -202,7 +217,7 @@ async function onAccount() {
owner_key: createAccountForm.value.owner_key,
active_key: createAccountForm.value.active_key,
});
handleAnswer(result, 'Account created successfully');
handleAnswer(result, `Account created successfully! txn: ${result}`);
submitting.value = false;
} else {
if (!createAccountForm.value.available) {
Expand Down

0 comments on commit 44a8f55

Please sign in to comment.