Skip to content
Snippets Groups Projects
Verified Commit 6af1a76b authored by Mateusz Tyszczak's avatar Mateusz Tyszczak :scroll:
Browse files

Add toasts for account create and account update

parent 121d7d44
No related branches found
No related tags found
No related merge requests found
Pipeline #117662 passed
...@@ -10,6 +10,7 @@ import { useRouter } from 'vue-router'; ...@@ -10,6 +10,7 @@ import { useRouter } from 'vue-router';
import { getWax } from '@/stores/wax.store'; import { getWax } from '@/stores/wax.store';
import { useWalletStore } from '@/stores/wallet.store'; import { useWalletStore } from '@/stores/wallet.store';
import { AccountAuthorityUpdateOperation } from '@hiveio/wax'; import { AccountAuthorityUpdateOperation } from '@hiveio/wax';
import { toastError } from '@/lib/parse-error';
const settings = useSettingsStore(); const settings = useSettingsStore();
...@@ -31,27 +32,35 @@ onMounted(() => { ...@@ -31,27 +32,35 @@ onMounted(() => {
ownerKey.value = router.currentRoute.value.query.owner as string ?? null; ownerKey.value = router.currentRoute.value.query.owner as string ?? null;
}); });
const isLoading = ref<boolean>(false);
const updateAuthority = async() => { const updateAuthority = async() => {
if (!memoKey.value && !postingKey.value && !activeKey.value && !ownerKey.value) { try {
alert('Nothing to update'); isLoading.value = true;
return;
}
const wax = await getWax(); if (!memoKey.value && !postingKey.value && !activeKey.value && !ownerKey.value)
const tx = await wax.createTransaction(); throw new Error("Nothing to update");
const op = await AccountAuthorityUpdateOperation.createFor(wax, creator.value.startsWith('@') ? creator.value.slice(1) : creator.value);
if (memoKey.value) const wax = await getWax();
op.role("memo").set(memoKey.value); const tx = await wax.createTransaction();
if (postingKey.value) const op = await AccountAuthorityUpdateOperation.createFor(wax, creator.value.startsWith('@') ? creator.value.slice(1) : creator.value);
op.role("posting").add(postingKey.value); if (memoKey.value)
if (activeKey.value) op.role("memo").set(memoKey.value);
op.role("active").add(activeKey.value); if (postingKey.value)
if (ownerKey.value) op.role("posting").add(postingKey.value);
op.role("owner").add(ownerKey.value); if (activeKey.value)
tx.pushOperation(op); op.role("active").add(activeKey.value);
const signature = await wallet.wallet!.signTransaction(tx, ownerKey.value ? "owner" : "active"); if (ownerKey.value)
tx.sign(signature); op.role("owner").add(ownerKey.value);
await wax.broadcast(tx); tx.pushOperation(op);
const signature = await wallet.wallet!.signTransaction(tx, ownerKey.value ? "owner" : "active");
tx.sign(signature);
await wax.broadcast(tx);
} catch (error) {
toastError('Error updating authority', error);
} finally {
isLoading.value = false;
}
} }
</script> </script>
...@@ -86,7 +95,7 @@ const updateAuthority = async() => { ...@@ -86,7 +95,7 @@ const updateAuthority = async() => {
<Label for="updateAuthority_ownerKey">Add Owner Key</Label> <Label for="updateAuthority_ownerKey">Add Owner Key</Label>
<Input id="updateAuthority_ownerKey" placeholder="Nothing to add" v-model="ownerKey" class="my-2" /> <Input id="updateAuthority_ownerKey" placeholder="Nothing to add" v-model="ownerKey" class="my-2" />
</div> </div>
<Button class="my-2" @click="updateAuthority">Update Authority</Button> <Button class="my-2" @click="updateAuthority" :disabled="isLoading">Update Authority</Button>
<p>Note: By clicking the above button, the transaction will be created, signed, and broadcasted immediately to the mainnet chain</p> <p>Note: By clicking the above button, the transaction will be created, signed, and broadcasted immediately to the mainnet chain</p>
</div> </div>
</CardContent> </CardContent>
......
...@@ -12,6 +12,7 @@ import { onMounted, ref } from 'vue'; ...@@ -12,6 +12,7 @@ import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { getWax } from '@/stores/wax.store'; import { getWax } from '@/stores/wax.store';
import { useWalletStore } from '@/stores/wallet.store'; import { useWalletStore } from '@/stores/wallet.store';
import { toastError } from '@/lib/parse-error';
const settings = useSettingsStore(); const settings = useSettingsStore();
...@@ -39,69 +40,79 @@ onMounted(() => { ...@@ -39,69 +40,79 @@ onMounted(() => {
ownerKey.value = router.currentRoute.value.query.owner as string ?? ''; ownerKey.value = router.currentRoute.value.query.owner as string ?? '';
}); });
const isLoading = ref<boolean>(false);
const createAccount = async() => { const createAccount = async() => {
const wax = await getWax(); try {
const tx = await wax.createTransaction(); isLoading.value = true;
const { median_props: { account_creation_fee } } = await wax.api.database_api.get_witness_schedule({});
const commonAccountCreateConfig = {
creator: settings.account!,
new_account_name: accountName.value.startsWith('@') ? accountName.value.slice(1) : accountName.value,
memo_key: memoKey.value,
owner: {
weight_threshold: 1,
key_auths: {[ownerKey.value]: 1},
account_auths: {}
},
active: {
weight_threshold: 1,
key_auths: {[activeKey.value]: 1},
account_auths: {}
},
posting: {
weight_threshold: 1,
key_auths: {[postingKey.value]: 1},
account_auths: {}
},
json_metadata: postingMetadata.value,
fee: account_creation_fee
};
if (createAccountType.value === "claimed") { const wax = await getWax();
tx.pushOperation({ const tx = await wax.createTransaction();
create_claimed_account: { const { median_props: { account_creation_fee } } = await wax.api.database_api.get_witness_schedule({});
...commonAccountCreateConfig, const commonAccountCreateConfig = {
extensions: [] creator: settings.account!,
} new_account_name: accountName.value.startsWith('@') ? accountName.value.slice(1) : accountName.value,
}); memo_key: memoKey.value,
if (enableDelegation.value) { owner: {
tx.pushOperation({ weight_threshold: 1,
delegate_vesting_shares: { key_auths: {[ownerKey.value]: 1},
delegator: settings.account!, account_auths: {}
delegatee: accountName.value.startsWith('@') ? accountName.value.slice(1) : accountName.value, },
vesting_shares: wax.vestsCoins(delegationAmount.value) active: {
} weight_threshold: 1,
}); key_auths: {[activeKey.value]: 1},
} account_auths: {}
} else { },
if (enableDelegation.value) { posting: {
weight_threshold: 1,
key_auths: {[postingKey.value]: 1},
account_auths: {}
},
json_metadata: postingMetadata.value,
fee: account_creation_fee
};
if (createAccountType.value === "claimed") {
tx.pushOperation({ tx.pushOperation({
account_create_with_delegation: { create_claimed_account: {
...commonAccountCreateConfig, ...commonAccountCreateConfig,
extensions: [], extensions: []
delegation: wax.vestsCoins(delegationAmount.value)
} }
}); });
if (enableDelegation.value) {
tx.pushOperation({
delegate_vesting_shares: {
delegator: settings.account!,
delegatee: accountName.value.startsWith('@') ? accountName.value.slice(1) : accountName.value,
vesting_shares: wax.vestsCoins(delegationAmount.value)
}
});
}
} else { } else {
tx.pushOperation({ if (enableDelegation.value) {
account_create: { tx.pushOperation({
...commonAccountCreateConfig account_create_with_delegation: {
} ...commonAccountCreateConfig,
}); extensions: [],
delegation: wax.vestsCoins(delegationAmount.value)
}
});
} else {
tx.pushOperation({
account_create: {
...commonAccountCreateConfig
}
});
}
} }
const signature = await wallet.wallet!.signTransaction(tx, "active");
tx.sign(signature);
await wax.broadcast(tx);
} catch (error) {
toastError('Error creating account', error);
} finally {
isLoading.value = false;
} }
const signature = await wallet.wallet!.signTransaction(tx, "active");
tx.sign(signature);
await wax.broadcast(tx);
} }
</script> </script>
...@@ -167,7 +178,7 @@ const createAccount = async() => { ...@@ -167,7 +178,7 @@ const createAccount = async() => {
<Label for="createAccount_r3">Create claimed</Label> <Label for="createAccount_r3">Create claimed</Label>
</div> </div>
</RadioGroup> </RadioGroup>
<Button @click="createAccount">Create account</Button> <Button @click="createAccount" :disabled="isLoading">Create account</Button>
<p>Note: By clicking the above button, the transaction will be created, signed, and broadcasted immediately to the mainnet chain</p> <p>Note: By clicking the above button, the transaction will be created, signed, and broadcasted immediately to the mainnet chain</p>
</div> </div>
</CardContent> </CardContent>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment