Skip to content

Commit

Permalink
feat: add staked balances to address page
Browse files Browse the repository at this point in the history
  • Loading branch information
leonimella committed Jan 28, 2025
1 parent 6ddb901 commit 9c9b9e2
Show file tree
Hide file tree
Showing 14 changed files with 588 additions and 460 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ NEXT_PUBLIC_GROWTH_BOOK_CLIENT_KEY=xxx
NEXT_PUBLIC_AUTH0_CLIENT_ID=xxx
FAVICON_GENERATOR_API_KEY=xxx
NEXT_PUBLIC_GROWTH_BOOK_CLIENT_KEY=xxx
NEXT_PUBLIC_MULTI_SHARDS_PROXY_URL=xxx
NEXT_PUBLIC_MULTI_SHARDS_PROXY_URL=xxx
NEXT_PUBLIC_STAKING_API_HOST=https://api.url
NEXT_PUBLIC_STAKING_API_NETWORK=testnet
2 changes: 2 additions & 0 deletions configs/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import chain from './chain';
import * as features from './features';
import meta from './meta';
import services from './services';
import stakingApi from './stakingApi';
import UI from './ui';

const config = Object.freeze({
Expand All @@ -14,6 +15,7 @@ const config = Object.freeze({
features,
services,
meta,
stakingApi,
});

export default config;
12 changes: 12 additions & 0 deletions configs/app/stakingApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getEnvValue } from './utils';

const apiEndpoint = getEnvValue('NEXT_PUBLIC_STAKING_API_HOST');
const apiNetwork = getEnvValue('NEXT_PUBLIC_STAKING_API_NETWORK');

const stakingApi = Object.freeze({
endpoint: apiEndpoint,
host: `${ apiEndpoint }/networks/${ apiNetwork }/delegations`,
network: apiNetwork,
});

export default stakingApi;
37 changes: 13 additions & 24 deletions nextjs/csp/policies/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import config from 'configs/app';

import { KEY_WORDS } from '../utils';

const MAIN_DOMAINS = [
`*.${ config.app.host }`,
config.app.host,
].filter(Boolean);
const MAIN_DOMAINS = [ `*.${ config.app.host }`, config.app.host ].filter(Boolean);

const getCspReportUrl = () => {
try {
Expand Down Expand Up @@ -67,15 +64,16 @@ export function app(): CspDev.DirectiveDescriptor {

// chain RPC server
config.chain.rpcUrl,
...(
getFeaturePayload(config.features.shards)?.shards ?
Object.values(getFeaturePayload(config.features.shards)?.shards || {}).map(shard => shard.chain.rpcUrl) :
[]
),
...(getFeaturePayload(config.features.shards)?.shards ?
Object.values(getFeaturePayload(config.features.shards)?.shards || {}).map((shard) => shard.chain.rpcUrl) :
[]),
'https://infragrid.v.network', // RPC providers

// github (spec for api-docs page)
'raw.githubusercontent.com',

// Staking API
config.stakingApi.endpoint,
].filter(Boolean),

'script-src': [
Expand Down Expand Up @@ -126,34 +124,25 @@ export function app(): CspDev.DirectiveDescriptor {
'*', // see comment for img-src directive
],

'font-src': [
KEY_WORDS.DATA,
...MAIN_DOMAINS,
],
'font-src': [ KEY_WORDS.DATA, ...MAIN_DOMAINS ],

'object-src': [
KEY_WORDS.NONE,
],
'object-src': [ KEY_WORDS.NONE ],

'base-uri': [
KEY_WORDS.NONE,
],
'base-uri': [ KEY_WORDS.NONE ],

'frame-src': [
// could be a marketplace app or NFT media (html-page)
'*',
],

...((() => {
...(() => {
if (!config.features.sentry.isEnabled) {
return {};
}

return {
'report-uri': [
getCspReportUrl(),
].filter(Boolean),
'report-uri': [ getCspReportUrl() ].filter(Boolean),
};
})()),
})(),
};
}
16 changes: 16 additions & 0 deletions types/api/stakingApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export type StakingApi = {
undelegations: Array<StakingApiUndelegations> | null;
amount: number | null;
delegator_address: string | null;
reward: number | null;
validator_address: string | null;
};

export type StakingApiUndelegations = {
Amount: number;
Epoch: number;
};

export type StakingApiFailed = StakingApi & {
fetchError: true;
};
3 changes: 2 additions & 1 deletion types/api/stakingTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export type StakingTransaction = {
msg_delegator_address: string;
msg_slot_pub_key_to_add: string;
msg_slot_pub_key_to_remove: string;
}
claimed_reward: string | null;
};
48 changes: 33 additions & 15 deletions types/api/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,26 @@ import type { TokenInfo } from './token';
import type { TokenTransfer } from './tokenTransfer';
import type { TxAction } from './txAction';

export type TransactionRevertReason = {
raw: string;
} | DecodedInput;
export type TransactionRevertReason =
| {
raw: string;
}
| DecodedInput;

type WrappedTransactionFields = 'decoded_input' | 'fee' | 'gas_limit' | 'gas_price' | 'hash' | 'max_fee_per_gas' |
'max_priority_fee_per_gas' | 'method' | 'nonce' | 'raw_input' | 'to' | 'type' | 'value';
type WrappedTransactionFields =
| 'decoded_input'
| 'fee'
| 'gas_limit'
| 'gas_price'
| 'hash'
| 'max_fee_per_gas'
| 'max_priority_fee_per_gas'
| 'method'
| 'nonce'
| 'raw_input'
| 'to'
| 'type'
| 'value';

export interface OpWithdrawal {
l1_transaction_hash: string;
Expand Down Expand Up @@ -78,7 +92,7 @@ export type Transaction = {
// zkEvm fields
zkevm_verify_hash?: string;
zkevm_batch_number?: number;
zkevm_status?: typeof ZKEVM_L2_TX_STATUSES[number];
zkevm_status?: (typeof ZKEVM_L2_TX_STATUSES)[number];
zkevm_sequence_hash?: string;
// blob tx fields
blob_versioned_hashes?: Array<string>;
Expand All @@ -88,7 +102,10 @@ export type Transaction = {
max_fee_per_blob_gas?: string;
shard_id?: string;
to_shard_id?: string;
}
claimed_reward: string | null;
delegated_amount?: string;
undelegated_amount?: string;
};

export const ZKEVM_L2_TX_STATUSES = [ 'Confirmed by Sequencer', 'L1 Confirmed' ];

Expand Down Expand Up @@ -131,14 +148,15 @@ export interface TransactionsResponseWatchlist {
} | null;
}

export type TransactionType = 'rootstock_remasc' |
'rootstock_bridge' |
'token_transfer' |
'contract_creation' |
'contract_call' |
'token_creation' |
'coin_transfer' |
'blob_transaction'
export type TransactionType =
| 'rootstock_remasc'
| 'rootstock_bridge'
| 'token_transfer'
| 'contract_creation'
| 'contract_call'
| 'token_creation'
| 'coin_transfer'
| 'blob_transaction';

export type TxsResponse = TransactionsResponseValidated | TransactionsResponsePending | BlockTransactionsResponse;

Expand Down
Loading

0 comments on commit 9c9b9e2

Please sign in to comment.