From ded75e413a09d0559189a4c48926cb8a5b36748e Mon Sep 17 00:00:00 2001 From: Bobo Date: Sat, 13 Jan 2024 09:55:23 +0100 Subject: [PATCH] dApps registration for v3 (#1119) * 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 * 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 * 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 Co-authored-by: kahonnohak Co-authored-by: impelcrypto <92044428+impelcrypto@users.noreply.github.com> Co-authored-by: impelcrypto 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 Co-authored-by: Bobo * 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 Co-authored-by: Bobo Co-authored-by: Kahori Razzell Co-authored-by: kahonnohak 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 * 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 Co-authored-by: kahonnohak Co-authored-by: impelcrypto <92044428+impelcrypto@users.noreply.github.com> Co-authored-by: impelcrypto 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 Co-authored-by: Bobo * 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 Co-authored-by: Bobo Co-authored-by: Kahori Razzell Co-authored-by: kahonnohak 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 * 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 * 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 * 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 Co-authored-by: Gregory Luneau Co-authored-by: impelcrypto <92044428+impelcrypto@users.noreply.github.com> Co-authored-by: Ayumi Takahashi Co-authored-by: Kahori Razzell Co-authored-by: kahonnohak Co-authored-by: Kahori <77480847+Kahonnohak@users.noreply.github.com> --- src/components/common/TokenBalanceNative.vue | 7 ++- .../dapp-staking/register/RegisterDapp.vue | 6 +- .../register/styles/register.scss | 2 + src/hooks/dapps-staking/useSignPayload.ts | 5 +- src/i18n/en-US/index.ts | 6 +- src/staking-v3/components/DiscoverV3.vue | 3 + src/staking-v3/components/Owner.vue | 4 +- src/staking-v3/components/RegisterBanner.vue | 59 ++++++++++++++++++ .../components/my-staking/ModalUnbondDapp.vue | 4 +- src/staking-v3/hooks/index.ts | 1 + src/staking-v3/hooks/useDappStaking.ts | 12 +++- src/staking-v3/hooks/useDapps.ts | 19 +++++- src/staking-v3/hooks/useRegisterDapp.ts | 40 ++++++++++++ .../logic/services/DappStakingService.ts | 17 ++++- .../logic/services/DappStakingServiceV2V3.ts | 62 +++++++++++++++++++ .../logic/services/IDappStakingService.ts | 12 +++- src/staking-v3/logic/services/index.ts | 1 + src/staking-v3/store/getters.ts | 3 + src/staking-v3/store/mutations.ts | 4 ++ src/staking-v3/store/state.ts | 3 + src/store/dapp-staking/actions.ts | 22 ------- src/v2/app.container.ts | 9 +++ src/v2/symbols.ts | 1 + .../dappstaking-transactions.spec.ts | 2 +- 24 files changed, 261 insertions(+), 43 deletions(-) create mode 100644 src/staking-v3/components/RegisterBanner.vue create mode 100644 src/staking-v3/hooks/useRegisterDapp.ts create mode 100644 src/staking-v3/logic/services/DappStakingServiceV2V3.ts diff --git a/src/components/common/TokenBalanceNative.vue b/src/components/common/TokenBalanceNative.vue index f63387381..4e5e524d9 100644 --- a/src/components/common/TokenBalanceNative.vue +++ b/src/components/common/TokenBalanceNative.vue @@ -3,7 +3,7 @@ :balance="ethers.utils.formatEther(balance)" :text="text" :decimals="decimals" - :symbol="nativeTokenSymbol" + :symbol="showTokenSymbol ? nativeTokenSymbol : ''" /> @@ -32,6 +32,11 @@ export default defineComponent({ required: false, default: 3, }, + showTokenSymbol: { + type: Boolean, + required: false, + default: true, + }, }, setup() { const { nativeTokenSymbol } = useNetworkInfo(); diff --git a/src/components/dapp-staking/register/RegisterDapp.vue b/src/components/dapp-staking/register/RegisterDapp.vue index f128442c2..ef0db537a 100644 --- a/src/components/dapp-staking/register/RegisterDapp.vue +++ b/src/components/dapp-staking/register/RegisterDapp.vue @@ -1,7 +1,7 @@ + + + + diff --git a/src/staking-v3/components/my-staking/ModalUnbondDapp.vue b/src/staking-v3/components/my-staking/ModalUnbondDapp.vue index 8ebf0baba..7343e0f6e 100644 --- a/src/staking-v3/components/my-staking/ModalUnbondDapp.vue +++ b/src/staking-v3/components/my-staking/ModalUnbondDapp.vue @@ -112,7 +112,7 @@ export default defineComponent({ const nativeTokenImg = computed(() => 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(() => { @@ -123,7 +123,7 @@ export default defineComponent({ return minStakingAmount.value > Number(maxAmount.value) - Number(amount.value); }); const maxAmount = computed(() => { - 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())) diff --git a/src/staking-v3/hooks/index.ts b/src/staking-v3/hooks/index.ts index 4747d4274..9411d2f13 100644 --- a/src/staking-v3/hooks/index.ts +++ b/src/staking-v3/hooks/index.ts @@ -6,3 +6,4 @@ export * from './useDappStakingNavigation'; export * from './usePeriod'; export * from './useAprV3'; export * from './useVotingCountdown'; +export * from './useRegisterDapp'; diff --git a/src/staking-v3/hooks/useDappStaking.ts b/src/staking-v3/hooks/useDappStaking.ts index a7dd6d234..ecae1a589 100644 --- a/src/staking-v3/hooks/useDappStaking.ts +++ b/src/staking-v3/hooks/useDappStaking.ts @@ -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; @@ -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) { @@ -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 => { const stakingRepo = container.get(Symbols.DappStakingRepositoryV3); const tiers = await stakingRepo.getDappTiers(era); @@ -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) { @@ -564,5 +571,6 @@ export function useDappStaking() { fetchEraLengthsToStore, getUnclaimedDappRewardsPerPeriod, rewardExpiresInNextPeriod, + getStakerInfo, }; } diff --git a/src/staking-v3/hooks/useDapps.ts b/src/staking-v3/hooks/useDapps.ts index 4ddc71040..2d34098a6 100644 --- a/src/staking-v3/hooks/useDapps.ts +++ b/src/staking-v3/hooks/useDapps.ts @@ -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'; @@ -13,8 +19,8 @@ export function useDapps() { const registeredDapps = computed( () => store.getters['stakingV3/getRegisteredDapps'] ); - const allDapps = computed(() => store.getters['stakingV3/getDapps']); + const newDapps = computed(() => store.getters['stakingV3/getNewDapps']); const fetchDappsToStore = async (): Promise => { // Don't fetch if we already have dApps. @@ -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 { @@ -77,6 +84,11 @@ 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, @@ -84,5 +96,6 @@ export function useDapps() { fetchDappToStore, fetchStakeAmountsToStore, getDapp, + getDappByOwner, }; } diff --git a/src/staking-v3/hooks/useRegisterDapp.ts b/src/staking-v3/hooks/useRegisterDapp.ts new file mode 100644 index 000000000..e0fcb0471 --- /dev/null +++ b/src/staking-v3/hooks/useRegisterDapp.ts @@ -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(); + + const getDappAddressToRegister = async (): Promise => { + const service = container.get(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 }; +} diff --git a/src/staking-v3/logic/services/DappStakingService.ts b/src/staking-v3/logic/services/DappStakingService.ts index 8bbb7253f..669bb489c 100644 --- a/src/staking-v3/logic/services/DappStakingService.ts +++ b/src/staking-v3/logic/services/DappStakingService.ts @@ -1,5 +1,11 @@ import { inject, injectable } from 'inversify'; -import { CombinedDappInfo, DappStakeInfo, SingularStakingInfo, StakeAmount } from '../models'; +import { + CombinedDappInfo, + DappInfo, + DappStakeInfo, + SingularStakingInfo, + StakeAmount, +} from '../models'; import { IDappStakingService } from './IDappStakingService'; import { Symbols } from 'src/v2/symbols'; import { IDappStakingRepository, IDataProviderRepository } from '../repositories'; @@ -19,7 +25,9 @@ export class DappStakingService implements IDappStakingService { ) {} // @inheritdoc - public async getDapps(network: string): Promise { + public async getDapps( + network: string + ): Promise<{ fullInfo: CombinedDappInfo[]; chainInfo: DappInfo[] }> { Guard.ThrowIfUndefined(network, 'network'); const [storeDapps, chainDapps, tokenApiDapps] = await Promise.all([ @@ -30,6 +38,7 @@ export class DappStakingService implements IDappStakingService { // Map on chain and in store dApps const dApps: CombinedDappInfo[] = []; + const onlyChain: DappInfo[] = []; chainDapps.forEach((chainDapp) => { const storeDapp = storeDapps.find( (x) => x.address.toLowerCase() === chainDapp.address.toLowerCase() @@ -43,10 +52,12 @@ export class DappStakingService implements IDappStakingService { chain: chainDapp, dappDetails, }); + } else { + onlyChain.push(chainDapp); } }); - return dApps; + return { fullInfo: dApps, chainInfo: onlyChain }; } // @inheritdoc diff --git a/src/staking-v3/logic/services/DappStakingServiceV2V3.ts b/src/staking-v3/logic/services/DappStakingServiceV2V3.ts new file mode 100644 index 000000000..f7688fe30 --- /dev/null +++ b/src/staking-v3/logic/services/DappStakingServiceV2V3.ts @@ -0,0 +1,62 @@ +// Temporary service to be used on places (e.g. dApp registration) where different dApp staking +// service implementation (v2 or v3) is needed, depending on dApp staking version deployed on a node. +// TODO remove after Astar release. + +import { container } from 'src/v2/common'; +import { useDappStaking } from '../../hooks'; +import { IDappStakingService } from 'src/v2/services'; +import { IDappStakingService as IDappStakingServiceV3 } from '.'; +import { Symbols } from 'src/v2/symbols'; +import { inject, injectable } from 'inversify'; +import { IApi } from 'src/v2/integration'; +import { IDappStakingRepository as IDappStakingRepositoryV3 } from '../repositories'; +import { EditDappItem } from 'src/store/dapp-staking/state'; + +export interface IDappStakingServiceV2V3 { + getRegisteredContract(developerAddress: string): Promise; + + /** + * Gets dapp data from Firebase. + * @param contractAddress Dapp contract address. + * @param network Name of the network where dapp has been deployed. + * @param forEdit Flag to indicate if dapp data should be fetched with encoded images. + */ + getDapp( + contractAddress: string, + network: string, + forEdit?: boolean + ): Promise; +} + +@injectable() +export class DappStakingServiceV2V3 implements IDappStakingServiceV2V3 { + constructor( + @inject(Symbols.DefaultApi) private api: IApi, + @inject(Symbols.DappStakingService) private stakingV2: IDappStakingService, + @inject(Symbols.DappStakingRepositoryV3) private repositoryV3: IDappStakingRepositoryV3 + ) {} + + public async getRegisteredContract(developerAddress: string): Promise { + if (await this.isV3()) { + const allDapps = await this.repositoryV3.getChainDapps(); + const dapp = allDapps.find((d) => d.owner === developerAddress); + + return dapp?.address; + } else { + return await this.stakingV2.getRegisteredContract(developerAddress); + } + } + + public async getDapp( + contractAddress: string, + network: string, + forEdit?: boolean + ): Promise { + return await this.stakingV2.getDapp(contractAddress, network, forEdit); + } + + private async isV3() { + const api = await this.api.getApi(); + return api.query.hasOwnProperty('dappStaking'); + } +} diff --git a/src/staking-v3/logic/services/IDappStakingService.ts b/src/staking-v3/logic/services/IDappStakingService.ts index 45a99178e..ee9716fd6 100644 --- a/src/staking-v3/logic/services/IDappStakingService.ts +++ b/src/staking-v3/logic/services/IDappStakingService.ts @@ -1,4 +1,10 @@ -import { CombinedDappInfo, DappStakeInfo, SingularStakingInfo, StakeAmount } from '../models'; +import { + CombinedDappInfo, + DappInfo, + DappStakeInfo, + SingularStakingInfo, + StakeAmount, +} from '../models'; /** * @interface IDappStakingService interface for a service containing business logic for dapp staking. @@ -6,8 +12,10 @@ import { CombinedDappInfo, DappStakeInfo, SingularStakingInfo, StakeAmount } fro export interface IDappStakingService { /** * Gets the dapps for the given network. + * @param network Name of the network to get dapps for. + * @returns A map containing full dapps info (chain and firebase data) and chain info (only for new dapps not stored in firebase yet). */ - getDapps(network: string): Promise; + getDapps(network: string): Promise<{ fullInfo: CombinedDappInfo[]; chainInfo: DappInfo[] }>; /** * Invokes claim staker rewards, unstake and unlock calls. diff --git a/src/staking-v3/logic/services/index.ts b/src/staking-v3/logic/services/index.ts index b57372ea0..125f3fb29 100644 --- a/src/staking-v3/logic/services/index.ts +++ b/src/staking-v3/logic/services/index.ts @@ -1,3 +1,4 @@ export * from './IDappStakingService'; export * from './DappStakingService'; export * from './DappStakingServiceEvm'; +export * from './DappStakingServiceV2V3'; diff --git a/src/staking-v3/store/getters.ts b/src/staking-v3/store/getters.ts index 2d694cef8..be61d78c7 100644 --- a/src/staking-v3/store/getters.ts +++ b/src/staking-v3/store/getters.ts @@ -13,11 +13,13 @@ import { DAppTierRewards, TiersConfiguration, EraLengths, + DappInfo, } from '../logic'; export interface DappStakingGetters { getVersion(state: DappStakingState): string; getDapps(state: DappStakingState): CombinedDappInfo[]; + getNewDapps(state: DappStakingState): DappInfo[]; getRegisteredDapps(state: DappStakingState): CombinedDappInfo[]; getProtocolState(state: DappStakingState): ProtocolState | undefined; getLedger(state: DappStakingState): AccountLedger | undefined; @@ -33,6 +35,7 @@ export interface DappStakingGetters { const getters: GetterTree & DappStakingGetters = { getVersion: (state) => state.version, getDapps: (state) => state.dapps, + getNewDapps: (state) => state.newDapps, getRegisteredDapps: (state) => state.dapps.filter((x) => x.chain.state === DappState.Registered), getProtocolState: (state) => state.protocolState, getLedger: (state) => state.ledger, diff --git a/src/staking-v3/store/mutations.ts b/src/staking-v3/store/mutations.ts index db74baf1e..e49ba51c8 100644 --- a/src/staking-v3/store/mutations.ts +++ b/src/staking-v3/store/mutations.ts @@ -18,6 +18,7 @@ import { export interface DappStakingMutations { addDapps(state: DappStakingState, dapps: CombinedDappInfo[]): void; + addNewDapps(state: DappStakingState, dapps: DappInfo[]): void; addDapp(state: DappStakingState, dapp: CombinedDappInfo): void; updateDappExtended(state: DappStakingState, dapp: Dapp): void; updateDappChain(state: DappStakingState, dapp: DappInfo): void; @@ -56,6 +57,9 @@ const mutations: MutationTree & DappStakingMutations = { addDapps(state, dapps) { state.dapps = dapps; }, + addNewDapps(state, dapps) { + state.newDapps = dapps; + }, addDapp(state, dapp) { state.dapps.push(dapp); }, diff --git a/src/staking-v3/store/state.ts b/src/staking-v3/store/state.ts index c819784b5..84453bfad 100644 --- a/src/staking-v3/store/state.ts +++ b/src/staking-v3/store/state.ts @@ -9,11 +9,13 @@ import { DAppTierRewards, TiersConfiguration, EraLengths, + DappInfo, } from '../logic'; export interface DappStakingState { version: string; dapps: CombinedDappInfo[]; + newDapps: DappInfo[]; protocolState: ProtocolState | undefined; ledger: AccountLedger | undefined; stakerInfo: Map | undefined; @@ -29,6 +31,7 @@ function state(): DappStakingState { return { version: '3.0.0', dapps: [], + newDapps: [], protocolState: undefined, ledger: undefined, stakerInfo: undefined, diff --git a/src/store/dapp-staking/actions.ts b/src/store/dapp-staking/actions.ts index 1fa7c4389..dc44078db 100644 --- a/src/store/dapp-staking/actions.ts +++ b/src/store/dapp-staking/actions.ts @@ -125,28 +125,6 @@ const actions: ActionTree = { async registerDappApi({ commit, dispatch }, parameters: RegisterParameters): Promise { if (parameters.api) { try { - if (!parameters.signature) { - // If no signature received, it means we are using the - // old dapp registration logic (to be removed after all networks are updated.) - const transaction = parameters.api.tx.dappsStaking.register( - getDappAddressEnum(parameters.dapp.address) - ); - - const signedTransaction = await sign({ - transaction, - senderAddress: parameters.senderAddress, - substrateAccounts: parameters.substrateAccounts, - isCustomSignature: parameters.isCustomSignature, - dispatch, - tip: parameters.tip, - getCallFunc: parameters.getCallFunc, - }); - - if (signedTransaction) { - parameters.signature = signedTransaction.toJSON(); - } - } - const payload = { name: parameters.dapp.name, iconFile: getFileInfo(parameters.dapp.iconFileName, parameters.dapp.iconFile), diff --git a/src/v2/app.container.ts b/src/v2/app.container.ts index 73285e5c8..d3760ba3b 100644 --- a/src/v2/app.container.ts +++ b/src/v2/app.container.ts @@ -79,6 +79,10 @@ import { xcmToken, XcmTokenInformation } from 'src/modules/xcm'; import { XvmRepository } from 'src/v2/repositories/implementations/XvmRepository'; import { XvmService } from 'src/v2/services/implementations/XvmService'; import { IdentityRepository } from './repositories/implementations/IdentityRepository'; +import { + DappStakingServiceV2V3, + IDappStakingServiceV2V3, +} from 'src/staking-v3/logic/services/DappStakingServiceV2V3'; import { IDataProviderRepository, TokenApiProviderRepository } from '../staking-v3/logic'; let currentWalletType = WalletType.Polkadot; @@ -220,6 +224,11 @@ export default function buildDependencyContainer(network: endpointKey): void { ); }); + container.addSingleton( + DappStakingServiceV2V3, + Symbols.DappStakingServiceV2V3 + ); + // Start block change subscription. Needed for remaining unlocking blocks calculation. container.get(Symbols.SystemRepository).startBlockSubscription(); } diff --git a/src/v2/symbols.ts b/src/v2/symbols.ts index 76b3670c9..df0e7c346 100644 --- a/src/v2/symbols.ts +++ b/src/v2/symbols.ts @@ -40,5 +40,6 @@ export const Symbols = { DappStakingServiceV3: Symbol.for('DappStakingServiceV3'), DappStakingServiceEvmV3: Symbol.for('DappStakingServiceEvmV3'), DappStakingServiceFactoryV3: Symbol.for('DappStakingServiceFactoryV3'), + DappStakingServiceV2V3: Symbol.for('DappStakingServiceV2V3'), TokenApiProviderRepository: Symbol.for('TokenApiProviderRepository'), }; diff --git a/tests/test_specs/dappstaking-transactions.spec.ts b/tests/test_specs/dappstaking-transactions.spec.ts index cecc3a9ac..c214cfe4c 100644 --- a/tests/test_specs/dappstaking-transactions.spec.ts +++ b/tests/test_specs/dappstaking-transactions.spec.ts @@ -77,7 +77,7 @@ test.describe('dApp staking transactions', () => { page .locator('div') .filter({ - hasText: /^Account must hold amount greater than 10ASTR in transferrable after you stake\.$/, + hasText: /^Account must hold amount greater than 10ASTR in transferable after you stake\.$/, }) .locator('span') ).toBeVisible();