Skip to content

Commit

Permalink
dApps registration for v3 (#1119)
Browse files Browse the repository at this point in the history
* Defined v3 project structure

* Stake, unstake skeletons

* Code organization improvements

* Get protocol state

* Protocol change notification message

* Lock and stake

* Read account ledger

* Unstake call

* unstake and unlock, claim staker

* Staker info

* Started with can stake logic

* Updated node types

* Staker reward calculation part 1

* Staker rewards calculation part 2

* dApp rewards calculation and claim

* Calculate and claim bonus rewards

* Calculate claim staker batch size fix

* Rewards fetch fix

* can claim methods

* Can Claim bug fix

* feat: Prevents Errors from Occuring (#1026)

* Prevents UnavailableStakeFunds

* rephrase

* Prevent tooManyStakedContracts, unclaimedRewardsFromPastPeriods

* less logs

* unstake Prevents UnstakeAmountTooLarge ZeroAmount Disabled

* UnclaimedRewardsFromPastPeriods

* feat: added top page (#1033)

* Vote mobile page and logic (#1036)

* Voting page created

* Voting page - part 1

* Vote logic

---------

Co-authored-by: impelcrypto <impelcrypto@gmail.com>

* Vote batch bug fixes

* vote and dictionary changes (#1037)

* vote and dictionary changes

* fix value and more

* vote checks

* Vote on multiple dApps  (#1046)

* FeatureDapp logic

* Search dApps

* Implemented stake on multiple dApps

* dApp tiers

* Switch periods on UI

* Removed separate link for staking v3

* Dapp rewards per period calculation

* feat: link to the project page (#1049)

* feat: link to the project page

* fix: display dapp data

* fix: clean up

* fix: clean up

* fix: clean up

* styles: added 'current tier' and 'total earned' (#1053)

* pulled latest main branch (#1057)

* merge the `release-hotfix` to `main` branch (#1025)

* fix: enables Snap on the production (#1024)

* Add a link to the docs (#1027)

* fix: words (#1028)

* fix: display the staking list for EVM accounts (#1030)

---------

Co-authored-by: Ayumi Takahashi <ayumee528@gmail.com>

* dApp fetching optimization (#1041)

* dApp fetching optimization

* An additional tiny optimization

* Update assets page layout (#956)

* Update assets page layout

* style update

* clean up

* replace transfer button to icon

* Align icon buttons on the right side

* Add navy-4 colour

* Update text color from default black to navy-1

* align token balance positions

* Adjust breakpoint for account section

* fix pointer events depends on screen size

* use i18n

* update asset search style

* Add faucet icon

* align token balance

* add reward animation

* remove static texts from account section

* Update AstarUI and replace icons

* remove claim button from reward section

* fix rewards section

* fix background image

* set max width

* update styles

* update delete button style

* move reward button next to account info

* Header style update

* update header color

* Add border color variation

* update to simple style

* remove old background image

* fix account icon size

* update sidebar size

* add border color for zKatana

* Update header icon styles

* update

* update style

* add icons

* Ads

* remove dynamic links

* update asset page style

* adjust border thickness 3px

* add background images

* add accout background

* update evm native token section style

* add ads style

* asset page wrapper space

* update header style

* add mobile nav

* Update styles

* add side ad area

* update Erx20Currency

* update account bg

* Add Rewards section

* Add rewards style

* update mobile nav

* update rewards style

* add mobile nav

* hide expand icon for mobile

* remove duplicated transfable

* display none

* revert

* Add assets list icon

* change-dark-bk

* add claim function

* fix mobile nav scroll

* update styles

* Remove transferable and comment out e2e test

* replace rewards section div to button

* add-account-images

* add shiden and testnet background

* Add transfer button for shibuya

* update native asset list style

* fix: updated rewards UI on the assets page (#1042)

* fix: fetch estimated rewards

* fix: updated rewards UI on the assets page

* fix: clean up

* fix: do not allow to select ZK network if the portal connects to native wallet

* fix: display background when the app is claiming rewards (#1045)

* fix: E2E test for new assets page  (#1044)

* fix: E2E test

* fix: E2E test (2)

* fix: remove --debug from 'playwright' command

* fix: include vesting amount in locked tokens (#1043)

* amend-style (#1047)

* fix: clean up

* fix: clean up

* use i18n

* clean up

* replace numers to endpointKey enum

* replace svg icons to astar ui

---------

Co-authored-by: Kahori Razzell <kahorirazzell@Kahoris-MacBook-Pro.local>
Co-authored-by: kahonnohak <kahon.nohak@gmail.com>
Co-authored-by: impelcrypto <92044428+impelcrypto@users.noreply.github.com>
Co-authored-by: impelcrypto <impelcrypto@gmail.com>
Co-authored-by: Kahori <77480847+Kahonnohak@users.noreply.github.com>

* fix-styling (#1054)

* merge 'release-hotfix' to 'main' (#1052)

* fix: enables Snap on the production (#1024)

* Add a link to the docs (#1027)

* fix: words (#1028)

* fix: display the staking list for EVM accounts (#1030)

* Ignore gas station (#1050)

* Ignore gas station

* Turned off Gas station everywhere

* Ignore another one gas station call

---------

Co-authored-by: Ayumi Takahashi <ayumee528@gmail.com>
Co-authored-by: Bobo <bobo.kovacevic@gmail.com>

* fix: resolved new assets page bugs (#1055)

* fix: close the modal after claiming EVM withdrawal

* fix: close the modal after claiming EVM withdrawal (2)

* fix: ModalVesting.vue

* fix: link to subscan for WASM projects

* feat: added Reserved section

* feat: added Reserved section (2)

* fix: words

* fix: refactor

---------

Co-authored-by: Ayumi Takahashi <ayumee528@gmail.com>
Co-authored-by: Bobo <bobo.kovacevic@gmail.com>
Co-authored-by: Kahori Razzell <kahorirazzell@Kahoris-MacBook-Pro.local>
Co-authored-by: kahonnohak <kahon.nohak@gmail.com>
Co-authored-by: Kahori <77480847+Kahonnohak@users.noreply.github.com>

* Staking panels and leaderboard (#1056)

* Get contract stake

* Initial leaderboard version

* voting call refactoring

* Tier rewards updates

* Leaderboard rendering fix

* My staking components

* Staking components logic done

* Re-lock unlocking chunks

* Unbonding modal

* Bonus rewards calculation bug fix

* Minor navigation refactoring

* Display total stake

* PropType fix

* Total stake calculation fix

* feat: added owner section on the assets page (#1059)

* merge the `release-hotfix` to `main` branch (#1025)

* fix: enables Snap on the production (#1024)

* Add a link to the docs (#1027)

* fix: words (#1028)

* fix: display the staking list for EVM accounts (#1030)

---------

Co-authored-by: Ayumi Takahashi <ayumee528@gmail.com>

* dApp fetching optimization (#1041)

* dApp fetching optimization

* An additional tiny optimization

* Update assets page layout (#956)

* Update assets page layout

* style update

* clean up

* replace transfer button to icon

* Align icon buttons on the right side

* Add navy-4 colour

* Update text color from default black to navy-1

* align token balance positions

* Adjust breakpoint for account section

* fix pointer events depends on screen size

* use i18n

* update asset search style

* Add faucet icon

* align token balance

* add reward animation

* remove static texts from account section

* Update AstarUI and replace icons

* remove claim button from reward section

* fix rewards section

* fix background image

* set max width

* update styles

* update delete button style

* move reward button next to account info

* Header style update

* update header color

* Add border color variation

* update to simple style

* remove old background image

* fix account icon size

* update sidebar size

* add border color for zKatana

* Update header icon styles

* update

* update style

* add icons

* Ads

* remove dynamic links

* update asset page style

* adjust border thickness 3px

* add background images

* add accout background

* update evm native token section style

* add ads style

* asset page wrapper space

* update header style

* add mobile nav

* Update styles

* add side ad area

* update Erx20Currency

* update account bg

* Add Rewards section

* Add rewards style

* update mobile nav

* update rewards style

* add mobile nav

* hide expand icon for mobile

* remove duplicated transfable

* display none

* revert

* Add assets list icon

* change-dark-bk

* add claim function

* fix mobile nav scroll

* update styles

* Remove transferable and comment out e2e test

* replace rewards section div to button

* add-account-images

* add shiden and testnet background

* Add transfer button for shibuya

* update native asset list style

* fix: updated rewards UI on the assets page (#1042)

* fix: fetch estimated rewards

* fix: updated rewards UI on the assets page

* fix: clean up

* fix: do not allow to select ZK network if the portal connects to native wallet

* fix: display background when the app is claiming rewards (#1045)

* fix: E2E test for new assets page  (#1044)

* fix: E2E test

* fix: E2E test (2)

* fix: remove --debug from 'playwright' command

* fix: include vesting amount in locked tokens (#1043)

* amend-style (#1047)

* fix: clean up

* fix: clean up

* use i18n

* clean up

* replace numers to endpointKey enum

* replace svg icons to astar ui

---------

Co-authored-by: Kahori Razzell <kahorirazzell@Kahoris-MacBook-Pro.local>
Co-authored-by: kahonnohak <kahon.nohak@gmail.com>
Co-authored-by: impelcrypto <92044428+impelcrypto@users.noreply.github.com>
Co-authored-by: impelcrypto <impelcrypto@gmail.com>
Co-authored-by: Kahori <77480847+Kahonnohak@users.noreply.github.com>

* fix-styling (#1054)

* merge 'release-hotfix' to 'main' (#1052)

* fix: enables Snap on the production (#1024)

* Add a link to the docs (#1027)

* fix: words (#1028)

* fix: display the staking list for EVM accounts (#1030)

* Ignore gas station (#1050)

* Ignore gas station

* Turned off Gas station everywhere

* Ignore another one gas station call

---------

Co-authored-by: Ayumi Takahashi <ayumee528@gmail.com>
Co-authored-by: Bobo <bobo.kovacevic@gmail.com>

* fix: resolved new assets page bugs (#1055)

* fix: close the modal after claiming EVM withdrawal

* fix: close the modal after claiming EVM withdrawal (2)

* fix: ModalVesting.vue

* fix: link to subscan for WASM projects

* feat: added Reserved section

* feat: added Reserved section (2)

* fix: words

* fix: refactor

* fix: display the amount of estimated rewards for Shibuya (#1058)

* feat: added owner page

* feat: added your-project section

* feat: resolve errors when the app connected to Astar

* feat: resolve errors when the app connected to Astar (2)

* feat: updated owner section

* fix: clean up

* fix: link to the owner page

---------

Co-authored-by: Ayumi Takahashi <ayumee528@gmail.com>
Co-authored-by: Bobo <bobo.kovacevic@gmail.com>
Co-authored-by: Kahori Razzell <kahorirazzell@Kahoris-MacBook-Pro.local>
Co-authored-by: kahonnohak <kahon.nohak@gmail.com>
Co-authored-by: Kahori <77480847+Kahonnohak@users.noreply.github.com>

* Staking v3 data (#1064)

* Data list component and refactoring

* Leader board properly assign tiers ans style improvements

* Day of a period calculation fix

* Prevent multiple dapps data loading

* Update src/App.vue

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

---------

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

* Compatibility issues fix (#1075)

* Refresh TVL on unstake

* Compatibility issues fix

* feat: maxUnlockingChunks (#1071)

* maxUnlockingChunks

* using getDapp method

* Remove commented

* feat: added owner section (#1079)

* feat: added rewards section

* feat: added edit section

* fix: refactor

* fix: i18

* fix: copy the project page components to the staking-v3 folder (#1085)

* fix: copy project page components to staking-v3 folder

* fix: updated astar.yml

* fix: rollback the endpoint in astar.yml

* Owner page logic and unstake from unregistered (#1088)

* Unstake from unregistered

* usePeriod hook

* era lengths

* Owner page logic

* Owner page fixes

* Fixes on your projects and dapp select modal

* Successful vote message

* Feat/staking v3 improvements4 (#1089)

* Unstake from unregistered

* usePeriod hook

* era lengths

* Owner page logic

* Owner page fixes

* Fixes on your projects and dapp select modal

* Successful vote message

* Leaderboard voting

* Group dApps by category

* Cleanup expired entries

* dApp page logic

* Minor Dapps component styling

* Select up to max number of staked contracts for voting

* Navigate to staking home if a dApp doesn't exists

* Add Shibuya Scope Style (#1078)

* add feature dApp area style

* add dapps list and data list area style

* add ad area style

* add Leaderboard area style

* move staking section to assets page

* update the your projects section style  on the assets page

* move css files

* add staking section style on the assets page

* add vote and stake page style

* adjust tvl text size

* add owner page style

* update astar ui

* remove dark theme style from the vote page

* update vote page style

* remove dark theme from dapp staking pages

* add project page style

* clean up

* add Leaderboard style

* update dapp style

* update lang

* add input search

* update

* update leaderboard style

* add category style

* add tier paging

* Small fix for loading a dApp

* Changed a way how to subscribe and handle protocol state

* clean up

* update dapps search logic

* remove operator from filter function

---------

Co-authored-by: Bobo <bobo.kovacevic@gmail.com>

* Show success messages and tier rewards (#1097)

* add feature dApp area style

* add dapps list and data list area style

* add ad area style

* add Leaderboard area style

* move staking section to assets page

* update the your projects section style  on the assets page

* move css files

* add staking section style on the assets page

* add vote and stake page style

* adjust tvl text size

* add owner page style

* update astar ui

* remove dark theme style from the vote page

* update vote page style

* remove dark theme from dapp staking pages

* add project page style

* clean up

* add Leaderboard style

* update dapp style

* update lang

* add input search

* Added success message to all calls

* update

* update leaderboard style

* add category style

* add tier paging

* Small fix for loading a dApp

* Changed a way how to subscribe and handle protocol state

* clean up

* update dapps search logic

* Show error message from canUnstake function

* Display tier daily rewards

---------

Co-authored-by: Ayumi Takahashi <ayumee528@gmail.com>

* dApp search bug fix, amount to be locked fix

* Build error fix

* Nomination transfer

* Disable Vote button if no stakes.

* Reward calculation fix, unlock

* v3 vote period style (#1098)

* remove the unnecessary div from assets page

* adjust vote page style

* add hover color to search, selector

* update vote page style

* add animated vote button

* add vote period hero

* update dapps slide style

* update leaderboard text

* update vote page column order

* Show nomination transfer info on Voting page

* feat: added EVM supports (#1102)

* Vote with EVM

* Fetch rewards for evm account

* feat: updated V3 via EVM logic (#1101)

* feat: updated claimUnstakeAndUnlock

* fix: clean up

* feat: added EVM calls

* fix: link to the vote page

* fix: clean up

* fix: conflicts (2)

* fix: claimUnstakeAndUnlock fn

* Build errors fix

* Build error fix 2

* Fix for initial loading of ledger and stakerInfo

* Ledger subscription fix

* Removed gas estimation

* refactor: added batch methods

* Remove senderSs58Account from hook since address mapping logic is moved to the service

* Disable canUnstake

* Linter fix

---------

Co-authored-by: Bobo <bobo.kovacevic@gmail.com>

* EVM unlock fix

* fix: added todo comment

* GetTier bug fix and removed some comments

* fix: removed unused files

* Comments cleanup

* Gas price provider fix

* Message subscriptions, check value before assignment.

* Nomination transfer bug fix, styling and translations

* Nomination transfer amount, total stake

* Leaderboard fix, multiplier removed

* Staker reward calculation optimisation

* Clam banner text update for Shibuya

* Voting period countdown

* Current period day and canConfirm fixes

* feat: update project page styles (#1109)

* add project icon background

* add project icon background to the owner page

* update all vote/stake button background

* fix app height

* move the register button to the assets page

* fix assets page container

* remove the license section from the project page

* made the header scroll

* add small dapp header

* fix v2 style

* remove the register banner from the assets page for now

* fix vote page layout

* fix vote period background

* adjust small header style and heart icon button

* update maintenance mode style

* update

* feat: add migrate support style (#1114)

* add migrate support style

* fix lang file

* Hide migration support for now

* feat: added staker and bonus rewards APR (#1113)

* feat: added useAprV3

* wip: staker rewards

* wip: staker rewards (2)

* wip: staker rewards (3)

* wip: staker rewards (4)

* wip: staker rewards (5)

* wip: staker rewards (6)

* wip: staker rewards (7)

* wip: staker rewards (8)

* feat: added basic rewards in the voting section

* fix: clean up

* fix: refactor

* feat: added bonus APR

* fix: clean up

* fix: set the periodsPerCycle from network name temporarily

* fix: set the periodsPerCycle from network name temporarily (2)

* Update to support v3 registration.

* Styling fix and cleanup

* URL fix

* Bug fix

* Typo fix

* Show number of staker on the owner page

* Fixed fetching staker info

---------

Co-authored-by: impelcrypto <impelcrypto@gmail.com>
Co-authored-by: Gregory Luneau <greg@astar.network>
Co-authored-by: impelcrypto <92044428+impelcrypto@users.noreply.github.com>
Co-authored-by: Ayumi Takahashi <ayumee528@gmail.com>
Co-authored-by: Kahori Razzell <kahorirazzell@Kahoris-MacBook-Pro.local>
Co-authored-by: kahonnohak <kahon.nohak@gmail.com>
Co-authored-by: Kahori <77480847+Kahonnohak@users.noreply.github.com>
  • Loading branch information
8 people committed Jan 13, 2024
1 parent c9e4b30 commit ded75e4
Show file tree
Hide file tree
Showing 24 changed files with 261 additions and 43 deletions.
7 changes: 6 additions & 1 deletion src/components/common/TokenBalanceNative.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:balance="ethers.utils.formatEther(balance)"
:text="text"
:decimals="decimals"
:symbol="nativeTokenSymbol"
:symbol="showTokenSymbol ? nativeTokenSymbol : ''"
/>
</template>

Expand Down Expand Up @@ -32,6 +32,11 @@ export default defineComponent({
required: false,
default: 3,
},
showTokenSymbol: {
type: Boolean,
required: false,
default: true,
},
},
setup() {
const { nativeTokenSymbol } = useNetworkInfo();
Expand Down
6 changes: 3 additions & 3 deletions src/components/dapp-staking/register/RegisterDapp.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="container--register">
<back-to-page :text="$t('dappStaking.stakePage.backToDappList')" :link="Path.DappStaking" />
<div class="wrapper--register-form">
<back-to-page :text="$t('dappStaking.stakePage.backToDappList')" :link="Path.DappStaking" />
<welcome-banner v-if="isNewDapp && !isMobileDevice" />
<desktop-only-banner v-if="isMobileDevice" />
<q-form v-if="!isMobileDevice" ref="dappForm">
Expand Down Expand Up @@ -124,7 +124,7 @@ import { isUrlValid } from 'src/components/common/Validators';
import { sanitizeData } from 'src/hooks/helper/markdown';
import { LabelValuePair } from './components/ItemsToggle.vue';
import { container } from 'src/v2/common';
import { IDappStakingService } from 'src/v2/services';
import { IDappStakingServiceV2V3 } from 'src/staking-v3/logic/services';
import { Symbols } from 'src/v2/symbols';
import { useStore } from 'src/store';
import { useCustomSignature, useGasPrice, useNetworkInfo, useSignPayload } from 'src/hooks';
Expand Down Expand Up @@ -245,7 +245,7 @@ export default defineComponent({
const getDapp = async (): Promise<void> => {
try {
store.commit('general/setLoading', true);
const service = container.get<IDappStakingService>(Symbols.DappStakingService);
const service = container.get<IDappStakingServiceV2V3>(Symbols.DappStakingServiceV2V3);
const developerContract =
currentAddress.value &&
!isH160.value &&
Expand Down
2 changes: 2 additions & 0 deletions src/components/dapp-staking/register/styles/register.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
justify-self: center;
padding-left: 24px;
padding-right: 24px;
z-index: 1;
position: relative;
@media (min-width: $lg) {
margin-top: 60px;
padding-left: 0px;
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/dapps-staking/useSignPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ import { $api } from 'src/boot/api';
import { getInjector } from 'src/hooks/helper/wallet';
import { useStore } from 'src/store';
import { getDappAddressEnum } from '@astar-network/astar-sdk-core';
import { useDappStaking } from 'src/staking-v3';

export function useSignPayload() {
const store = useStore();
const { isDappStakingV3 } = useDappStaking();
const selectedAddress = computed(() => store.getters['general/selectedAddress']);
const substrateAccounts = computed(() => store.getters['general/substrateAccounts']);

const signPayload = async (
developerAddress: string,
contractAddress: string
): Promise<string> => {
const payload = $api?.tx.dappsStaking
const palletName = isDappStakingV3.value ? 'dappStaking' : 'dappsStaking';
const payload = $api?.tx[palletName]
.register(developerAddress, getDappAddressEnum(contractAddress))
.toHex();
const injector = await getInjector(substrateAccounts.value);
Expand Down
6 changes: 4 additions & 2 deletions src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export default {
'All funds will be transferred because the min. staking amount is {minStakingAmount} {symbol}',
invalidBalance: 'You do not have enough tokens to pay the transaction fee',
warningLeaveMinAmount:
'Account must hold amount greater than {amount}{symbol} in transferrable after you stake.',
'Account must hold amount greater than {amount}{symbol} in transferable after you stake.',
},
maintenance: {
switching: 'Switching to',
Expand Down Expand Up @@ -728,7 +728,7 @@ export default {
stakeTitle: 'Stake!',
minimumStakingAmount: 'Minimum staking amount is {amount} {symbol}',
minBalanceAfterStaking:
'Account must hold more than {amount} {symbol} transferrable tokens after you stake.',
'Account must hold more than {amount} {symbol} transferable tokens after you stake.',
selectProjects: 'Select projects',
chooseProject: 'Choose a project to vote',
availableToVote: 'Available to vote',
Expand Down Expand Up @@ -828,6 +828,8 @@ export default {
startStakingNow: 'Start Staking Now',
noEntry: 'No entry',
burn: 'Burn',
dappRegistered: 'Congrats!! your contract is approved. Please submit the details',
registerNow: 'Register now',
willUnstakeAll:
'The operation will unstake all of your staked tokens because the minimum staking amount is {amount} tokens.',
},
Expand Down
3 changes: 3 additions & 0 deletions src/staking-v3/components/DiscoverV3.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div class="wrapper--discover">
<feature-dapp />
<!-- <staking /> -->
<register-banner />
<leaderboard />
<leaderboard-vote />
<dynamic-ads-area />
Expand Down Expand Up @@ -49,6 +50,7 @@ import { useDappStaking } from '../hooks';
import DynamicAdsArea from './DynamicAdsArea.vue';
import ToggleButtons from './ToggleButtons.vue';
import DataList from './data/DataList.vue';
import RegisterBanner from './RegisterBanner.vue';
export default defineComponent({
components: {
Expand All @@ -59,6 +61,7 @@ export default defineComponent({
DataList,
DynamicAdsArea,
ToggleButtons,
RegisterBanner,
},
setup() {
const displayIndex = ref<number>(0);
Expand Down
4 changes: 3 additions & 1 deletion src/staking-v3/components/Owner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<kpi-card :title="$t('stakingV3.currentTier')">{{
getDappTier(dapp.chain.id) ?? '--'
}}</kpi-card>
<kpi-card :title="$t('stakingV3.numberOfStakers')">--</kpi-card>
<kpi-card :title="$t('stakingV3.numberOfStakers')">
{{ dapp.dappDetails?.stakersCount ?? '--' }}
</kpi-card>
<kpi-card :title="$t('stakingV3.totalEarned')"> -- </kpi-card>
</div>
<your-rewards
Expand Down
59 changes: 59 additions & 0 deletions src/staking-v3/components/RegisterBanner.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<template>
<router-link
v-if="canRegister"
:to="networkParam + Path.DappStaking + Path.Register"
class="router"
>
<div class="register--container">
<div class="congrats">&#127881; {{ `${$t('stakingV3.dappRegistered')}` }}</div>
<div>{{ `${$t('stakingV3.registerNow')}` }}</div>
</div>
</router-link>
</template>

<script lang="ts">
import { computed, defineComponent, ref, watch } from 'vue';
import { networkParam, Path } from 'src/router/routes';
import { useRegisterDapp } from '../hooks';
export default defineComponent({
setup() {
const { dappAddressToRegister } = useRegisterDapp();
const canRegister = computed<boolean>(() => dappAddressToRegister.value !== undefined);
return {
canRegister,
networkParam,
Path,
};
},
});
</script>

<style lang="scss" scoped>
.router {
width: 100%;
}
.register--container {
display: flex;
justify-content: space-between;
background-color: $astar-blue;
border-radius: 6px;
padding: 16px;
cursor: pointer;
color: $gray-1;
font-size: 16px;
}
.register--container:hover {
outline: 1px solid $astar-blue;
}
.congrats {
color: $gray-1;
font-weight: 600;
font-size: 16px;
line-height: 19px;
}
</style>
4 changes: 2 additions & 2 deletions src/staking-v3/components/my-staking/ModalUnbondDapp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default defineComponent({
const nativeTokenImg = computed<string>(() =>
getTokenImage({ isNativeToken: true, symbol: nativeTokenSymbol.value })
);
const { stakerInfo, constants, unstake, canUnStake } = useDappStaking();
const { stakerInfo, constants, unstake, canUnStake, getStakerInfo } = useDappStaking();
const store = useStore();
const minStakingAmount = computed<number>(() => {
Expand All @@ -123,7 +123,7 @@ export default defineComponent({
return minStakingAmount.value > Number(maxAmount.value) - Number(amount.value);
});
const maxAmount = computed<string>(() => {
const selectedDappStakes = stakerInfo.value?.get(props.dapp.chain.address);
const selectedDappStakes = getStakerInfo(props.dapp.chain.address);
return selectedDappStakes
? String(ethers.utils.formatEther(selectedDappStakes.staked.totalStake.toString()))
Expand Down
1 change: 1 addition & 0 deletions src/staking-v3/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './useDappStakingNavigation';
export * from './usePeriod';
export * from './useAprV3';
export * from './useVotingCountdown';
export * from './useRegisterDapp';
12 changes: 10 additions & 2 deletions src/staking-v3/hooks/useDappStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ethers } from 'ethers';
import { initialDappTiersConfiguration, initialTiersConfiguration } from '../store/state';
import { checkIsDappStakingV3 } from 'src/modules/dapp-staking';
import { ApiPromise } from '@polkadot/api';
import { isValidEvmAddress } from '@astar-network/astar-sdk-core';

export interface RewardsPerPeriod {
period: number;
Expand Down Expand Up @@ -424,7 +425,7 @@ export function useDappStaking() {

const canUnStake = (dappAddress: string, amount: number): [boolean, string] => {
const unstakeAmount = BigInt(ethers.utils.parseEther(amount.toString()).toString());
const dappInfo = stakerInfo.value.get(dappAddress);
const dappInfo = getStakerInfo(dappAddress);
const stakedAmount = dappInfo?.staked.totalStake ?? BigInt(0);

if (amount <= 0) {
Expand Down Expand Up @@ -454,6 +455,12 @@ export function useDappStaking() {
return [true, ''];
};

const getStakerInfo = (dappAddress: string): SingularStakingInfo | undefined => {
const isEvmAddress = isValidEvmAddress(dappAddress);

return stakerInfo.value?.get(isEvmAddress ? dappAddress.toLowerCase() : dappAddress);
};

const getDappTiers = async (era: number): Promise<void> => {
const stakingRepo = container.get<IDappStakingRepository>(Symbols.DappStakingRepositoryV3);
const tiers = await stakingRepo.getDappTiers(era);
Expand Down Expand Up @@ -509,7 +516,7 @@ export function useDappStaking() {
*/
const updateStakersCount = (stakedContracts: string[], amount: number): void => {
for (const contract of stakedContracts) {
const alreadyStaked = stakerInfo.value.get(contract);
const alreadyStaked = getStakerInfo(contract);
if (!alreadyStaked) {
const dapp = getDapp(contract);
if (dapp && dapp.dappDetails) {
Expand Down Expand Up @@ -564,5 +571,6 @@ export function useDappStaking() {
fetchEraLengthsToStore,
getUnclaimedDappRewardsPerPeriod,
rewardExpiresInNextPeriod,
getStakerInfo,
};
}
19 changes: 16 additions & 3 deletions src/staking-v3/hooks/useDapps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { computed } from 'vue';
import { container } from 'src/v2/common';
import { CombinedDappInfo, IDappStakingRepository, IDappStakingService } from '../logic';
import {
CombinedDappInfo,
DappInfo,
DappState,
IDappStakingRepository,
IDappStakingService,
} from '../logic';
import { Symbols } from 'src/v2/symbols';
import { useNetworkInfo } from 'src/hooks';
import { BusyMessage, IEventAggregator } from 'src/v2/messaging';
Expand All @@ -13,8 +19,8 @@ export function useDapps() {
const registeredDapps = computed<CombinedDappInfo[]>(
() => store.getters['stakingV3/getRegisteredDapps']
);

const allDapps = computed<CombinedDappInfo[]>(() => store.getters['stakingV3/getDapps']);
const newDapps = computed<DappInfo[]>(() => store.getters['stakingV3/getNewDapps']);

const fetchDappsToStore = async (): Promise<void> => {
// Don't fetch if we already have dApps.
Expand All @@ -29,7 +35,8 @@ export function useDapps() {
try {
aggregator.publish(new BusyMessage(true));
const dApps = await service.getDapps(currentNetworkName.value.toLowerCase());
store.commit('stakingV3/addDapps', dApps);
store.commit('stakingV3/addDapps', dApps.fullInfo);
store.commit('stakingV3/addNewDapps', dApps.chainInfo);
// Memo: this can a heavy operations since we are querying all dapps stakes for a chain.
await fetchStakeAmountsToStore();
} finally {
Expand Down Expand Up @@ -77,12 +84,18 @@ export function useDapps() {
const getDapp = (dappAddress: string): CombinedDappInfo | undefined =>
allDapps.value.find((d) => d.chain.address.toLowerCase() === dappAddress?.toLowerCase());

const getDappByOwner = (ownerAddress: string): DappInfo | undefined => {
const dapps = [...allDapps.value.map((x) => x.chain), ...newDapps.value];
return dapps.find((d) => d.owner === ownerAddress && d.state === DappState.Registered);
};

return {
registeredDapps,
allDapps,
fetchDappsToStore,
fetchDappToStore,
fetchStakeAmountsToStore,
getDapp,
getDappByOwner,
};
}
40 changes: 40 additions & 0 deletions src/staking-v3/hooks/useRegisterDapp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { watch, ref } from 'vue';
import { container } from 'src/v2/common';
import { IDappStakingServiceV2V3 } from '../logic';
import { Symbols } from 'src/v2/symbols';
import { useAccount, useNetworkInfo } from 'src/hooks';
import { useDapps } from './useDapps';

export function useRegisterDapp() {
const { currentAccount, isH160Formatted } = useAccount();
const { getDappByOwner } = useDapps();
const { currentNetworkName } = useNetworkInfo();

const dappAddressToRegister = ref<string | undefined>();

const getDappAddressToRegister = async (): Promise<string | undefined> => {
const service = container.get<IDappStakingServiceV2V3>(Symbols.DappStakingServiceV2V3);
const developerContract =
currentAccount.value && !isH160Formatted.value
? getDappByOwner(currentAccount.value)?.address
: undefined;
if (developerContract) {
const dapp = await service.getDapp(developerContract, currentNetworkName.value);
return dapp === undefined ? developerContract : undefined;
}

return undefined;
};

watch(
[currentAccount],
async () => {
if (currentAccount) {
dappAddressToRegister.value = await getDappAddressToRegister();
}
},
{ immediate: true }
);

return { dappAddressToRegister };
}
Loading

0 comments on commit ded75e4

Please sign in to comment.