Skip to content

Commit

Permalink
feat: migrate business logic in dApp staking v2 to v2(new) architectu…
Browse files Browse the repository at this point in the history
…re (#662)

* feat: made a template structure for dapp-staking v2

* refactor: cleanup

* refactor useStakerInfo hook (#664)

* add getStakeInfo function in repo

* migrate getStake function to v2

* fix: modified fetching 'My staking information' logic when users change the account (#666)

Co-authored-by: impelcrypto <92044428+impelcrypto@users.noreply.github.com>

* Refactor/unbonding hook (#670)

* diminish snowpack & put space on tvl text (#663)

* feat:Support for BNC and vDOT assets (#658)

* feat:Support for BNC and vDOT assets

* Fix some errors

* Update BifrostXcmRepository.ts

* Add some constants

* 0.0.9

* feat: updated japanese translation (#665)

* go back logo (#667)

* migrate for useUnbonding hook

Co-authored-by: NingBo Wang <2536935847@qq.com>
Co-authored-by: github-actions <github-actions@users.noreply.github.com>
Co-authored-by: impelcrypto <92044428+impelcrypto@users.noreply.github.com>

---------

Co-authored-by: Will <korea651@hanmail.net>
Co-authored-by: NingBo Wang <2536935847@qq.com>
Co-authored-by: github-actions <github-actions@users.noreply.github.com>
  • Loading branch information
4 people committed Feb 8, 2023
1 parent 38c483c commit f087772
Show file tree
Hide file tree
Showing 21 changed files with 296 additions and 288 deletions.
2 changes: 1 addition & 1 deletion src/components/common/FormatBalance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineComponent({
components: { Balance },
props: {
balance: {
type: Object as PropType<BN> | Object as PropType<string> | undefined,
type: Object as PropType<BN> | PropType<string> | undefined,
required: true,
},
},
Expand Down
8 changes: 7 additions & 1 deletion src/components/dapp-staking/my-staking/MyDapps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
</template>

<modal-unbond-dapp
v-model:is-open="showModalUnbond"
v-if="selectedDapp"
:set-is-open="setShowModalUnbond"
:show="showModalUnbond"
:dapp="selectedDapp"
/>
Expand Down Expand Up @@ -108,6 +109,10 @@ export default defineComponent({
const router = useRouter();
const showModalUnbond = ref<boolean>(false);
const setShowModalUnbond = (isOpen: boolean): void => {
showModalUnbond.value = isOpen;
};
const isUnregistered = (info: MyStakeInfo): boolean => {
return !info.isRegistered && info.stakersCount > 0;
};
Expand Down Expand Up @@ -135,6 +140,7 @@ export default defineComponent({
canClaim,
claimAll,
isUnregistered,
setShowModalUnbond,
};
},
});
Expand Down
7 changes: 6 additions & 1 deletion src/components/dapp-staking/my-staking/UnbondingList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<Teleport to="#app--main">
<div>
<modal-withdraw
v-model:is-open="showModalWithdraw"
:set-is-open="setShowModalWithdraw"
:show="showModalWithdraw"
:withdraw-amount="totalAmount"
@confirm="withdraw"
Expand Down Expand Up @@ -79,6 +79,10 @@ export default defineComponent({
const { withdraw } = useUnbonding();
const showModalWithdraw = ref(false);
const setShowModalWithdraw = (isOpen: boolean): void => {
showModalWithdraw.value = isOpen;
};
const showModalRebond = ref(false);
// MEMO: since not possible to withdraw each chunk currently, use total amount of withdraw
const totalAmount = ref('');
Expand Down Expand Up @@ -112,6 +116,7 @@ export default defineComponent({
showWithdrawDialog,
showRebondDialog,
withdraw,
setShowModalWithdraw,
};
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export default defineComponent({
type: Object as PropType<MyStakeInfo | undefined>,
required: true,
},
setIsOpen: {
type: Function,
required: true,
},
},
setup(props, { emit }) {
const { unbondingPeriod, handleUnbound } = useUnbound();
Expand Down Expand Up @@ -117,13 +121,13 @@ export default defineComponent({
const closeModal = async (): Promise<void> => {
isClosingModal.value = true;
await wait(fadeDuration);
emit('update:is-open', false);
props.setIsOpen(false);
isClosingModal.value = false;
};
const unbound = async (): Promise<void> => {
await handleUnbound(props.dapp?.dappAddress, amount.value);
await closeModal();
await handleUnbound(props.dapp?.dappAddress, amount.value);
};
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ export default defineComponent({
type: String,
default: null,
},
setIsOpen: {
type: Function,
required: true,
},
},
emits: ['update:is-open', 'confirm'],
setup(props, { emit }) {
const isClosingModal = ref<boolean>(false);
const closeModal = async (): Promise<void> => {
isClosingModal.value = true;
await wait(fadeDuration);
emit('update:is-open', false);
props.setIsOpen(false);
isClosingModal.value = false;
};
Expand Down
8 changes: 7 additions & 1 deletion src/components/dapp-staking/my-staking/items/MyDappItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
<Teleport to="#app--main">
<div :class="'highest-z-index'">
<modal-unbond-dapp
v-model:is-open="showModalUnbond"
v-if="selectedDapp"
:set-is-open="setShowModalUnbond"
:show="showModalUnbond"
:dapp="selectedDapp"
/>
Expand Down Expand Up @@ -81,6 +82,10 @@ export default defineComponent({
const router = useRouter();
const showModalUnbond = ref<boolean>(false);
const setShowModalUnbond = (isOpen: boolean): void => {
showModalUnbond.value = isOpen;
};
const isUnregistered = (info: MyStakeInfo): boolean =>
!info.isRegistered && info.stakersCount > 0;
Expand All @@ -105,6 +110,7 @@ export default defineComponent({
claimAll,
canClaim,
isUnregistered,
setShowModalUnbond,
};
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<Teleport to="#app--main">
<div :class="'highest-z-index'">
<modal-withdraw
v-model:is-open="showModalWithdraw"
:set-is-open="setShowModalWithdraw"
:show="showModalWithdraw"
:withdraw-amount="totalAmount"
@confirm="withdraw"
Expand Down Expand Up @@ -65,6 +65,10 @@ export default defineComponent({
},
setup() {
const showModalWithdraw = ref(false);
const setShowModalWithdraw = (isOpen: boolean): void => {
showModalWithdraw.value = isOpen;
};
const showModalRebond = ref(false);
// MEMO: since not possible to withdraw each chunk currently, use total amount of withdraw
const totalAmount = ref('');
Expand All @@ -88,6 +92,7 @@ export default defineComponent({
showWithdrawDialog,
showRebondDialog,
withdraw,
setShowModalWithdraw,
};
},
});
Expand Down
45 changes: 20 additions & 25 deletions src/hooks/custom-signature/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { hasExtrinsicFailedEvent } from 'src/store/dapp-staking/actions';

export enum TxType {
dappsStaking = 'dappsStaking',
requiredClaim = 'requiredClaim',
withdrawUnbonded = 'withdrawUnbonded',
}

// @TODO: we need to clean up this later in a way that can be solved without send over the store
export const displayCustomMessage = ({
txType,
store,
Expand All @@ -29,10 +30,11 @@ export const displayCustomMessage = ({
senderAddress,
t,
});
} else if (txType === TxType.requiredClaim) {
dispatchRequiredClaimMessage({
} else if (txType === TxType.withdrawUnbonded) {
dispatchUnbondedMessage({
result,
store,
senderAddress,
t,
});
}
Expand All @@ -49,7 +51,7 @@ const dispatchClaimMessage = ({
senderAddress: string;
t: (...arg: any) => void;
}): void => {
if (result.status.isFinalized) {
if (result.isCompleted) {
if (!hasExtrinsicFailedEvent(result.events, store.dispatch)) {
const totalClaimedStaker = calculateClaimedStaker({
events: result.events,
Expand Down Expand Up @@ -78,35 +80,28 @@ const dispatchClaimMessage = ({
}
};

const dispatchRequiredClaimMessage = ({
const dispatchUnbondedMessage = ({
store,
result,
senderAddress,
t,
}: {
store: Store<StateInterface>;
result: ISubmittableResult;
senderAddress: string;
t: (...arg: any) => void;
}): void => {
if (result.status.isFinalized) {
let errorMessage = '';
const res = hasExtrinsicFailedEvent(
result.events,
store.dispatch,
(message: string) => (errorMessage = message)
);
if (res) {
if (errorMessage.includes('TooManyEraStakeValues')) {
const msg = t('dappStaking.toast.requiredClaimFirst');

store.dispatch(
'general/showAlertMsg',
{
msg,
alertType: 'error',
},
{ root: true }
);
}
if (result.isCompleted) {
if (!hasExtrinsicFailedEvent(result.events, store.dispatch)) {
store.commit('dapps/setUnlockingChunks', -1);
store.dispatch(
'general/showAlertMsg',
{
msg: t('dappStaking.toast.successfullyWithdrew'),
alertType: 'success',
},
{ root: true }
);
}
}
};
Loading

0 comments on commit f087772

Please sign in to comment.