Skip to content

Commit

Permalink
Handle removal of unregistered dApps from a node storage (#1155) (#1161)
Browse files Browse the repository at this point in the history
* Handle removal of unregistered dApps from a note storage

* Map dapp id

Co-authored-by: Bobo <bobo.kovacevic@gmail.com>
  • Loading branch information
gluneau and bobo-k2 authored Jan 31, 2024
1 parent 8f6c17c commit 1782ada
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/staking-v3/hooks/useLeaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function useLeaderboard() {
);

const sortedDapps = computed<CombinedDappInfo[]>(() =>
registeredDapps.value.sort((a, b) => {
[...registeredDapps.value].sort((a, b) => {
const valueA = a.chain?.totalStake ?? BigInt(0);
const valueB = b.chain?.totalStake ?? BigInt(0);

Expand Down
1 change: 0 additions & 1 deletion src/staking-v3/logic/interfaces/DappStakingV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export interface PalletDappStakingV3ProtocolState extends Struct {
export interface PalletDappStakingV3DAppInfo extends Struct {
readonly owner: AccountId32;
readonly id: Compact<u16>;
readonly state: PalletDappStakingV3DAppState;
readonly rewardBeneficiary: Option<AccountId32>;
}

Expand Down
6 changes: 5 additions & 1 deletion src/staking-v3/logic/models/DappStaking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DappInfo, ProtocolState } from './Node';
import { DappInfo, DappState, ProtocolState } from './Node';
import { Community } from '@astar-network/astar-sdk-core';

/**
Expand Down Expand Up @@ -198,6 +198,10 @@ export interface ProviderDappData {
registrationBlockNumber: number;
unregisteredAt?: number;
unregistrationBlockNumber?: number;
owner: string;
beneficiary?: string;
state: DappState;
dappId: number;
}

export interface NumberOfParticipantsData {
Expand Down
2 changes: 1 addition & 1 deletion src/staking-v3/logic/repositories/DappStakingRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ export class DappStakingRepository implements IDappStakingRepository {
address,
owner: dapp.owner.toString(),
id: dapp.id.toNumber(),
state: dapp.state.isUnregistered ? DappState.Unregistered : DappState.Registered,
state: DappState.Registered, // All dApss from integratedDApps are registered.
rewardDestination: dapp.rewardBeneficiary.unwrapOr(undefined)?.toString(),
};
}
Expand Down
24 changes: 23 additions & 1 deletion src/staking-v3/logic/services/DappStakingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CombinedDappInfo,
DappInfo,
DappStakeInfo,
DappState,
SingularStakingInfo,
StakeAmount,
StakerRewards,
Expand Down Expand Up @@ -37,7 +38,7 @@ export class DappStakingService implements IDappStakingService {
this.tokenApiRepository.getDapps(network.toLowerCase()),
]);

// Map on chain and in store dApps
// Map on chain and in store dApps (registered only)
const dApps: CombinedDappInfo[] = [];
const onlyChain: DappInfo[] = [];
chainDapps.forEach((chainDapp) => {
Expand All @@ -58,6 +59,27 @@ export class DappStakingService implements IDappStakingService {
}
});

// Map unregistered dApps
tokenApiDapps
.filter((x) => x.state === 'Unregistered')
.forEach((dapp) => {
const storeDapp = storeDapps.find(
(x) => x.address.toLowerCase() === dapp.contractAddress.toLowerCase()
);
if (storeDapp) {
dApps.push({
basic: storeDapp,
dappDetails: dapp,
chain: {
address: dapp.contractAddress,
id: dapp.dappId,
owner: dapp.owner,
state: DappState.Unregistered,
},
});
}
});

return { fullInfo: dApps, chainInfo: onlyChain };
}

Expand Down

0 comments on commit 1782ada

Please sign in to comment.