Skip to content

Commit

Permalink
Merge branch 'develop' into chore/stake-pool-components-with-graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyslbw authored Sep 23, 2020
2 parents 8dcb19b + 73bf657 commit 95cc20b
Show file tree
Hide file tree
Showing 23 changed files with 369 additions and 110 deletions.
45 changes: 33 additions & 12 deletions source/features/address/api/transformers.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
import { Currency } from 'cardano-js';
import { SearchForAddressQuery } from '../../../../generated/typings/graphql-schema';
import { IAddressSummary } from '../types';
import {
SearchForPaymentAddressQuery,
SearchForStakeAddressQuery,
} from '../../../../generated/typings/graphql-schema';
import { IPaymentAddressSummary, IStakeAddressSummary } from '../types';

export const addressDetailTransformer = (
export const paymentAddressDetailTransformer = (
address: string,
s: SearchForAddressQuery
): IAddressSummary => ({
address,
finalBalance: Currency.Util.lovelacesToAda(
s.utxos_aggregate?.aggregate?.sum?.value || '0'
),
transactionsCount:
s.transactions_aggregate?.aggregate?.count.toString() || '0',
});
s: SearchForPaymentAddressQuery
): IPaymentAddressSummary => {
return {
address,
finalBalance: Currency.Util.lovelacesToAda(
s.utxos_aggregate?.aggregate?.sum?.value || '0'
),
transactionsCount:
s.transactions_aggregate?.aggregate?.count.toString() || '0'
}
};

export const stakeAddressDetailTransformer = (
address: string,
s: SearchForStakeAddressQuery
): IStakeAddressSummary => {
return {
address,
totalWithdrawals:
s.withdrawals_aggregate?.aggregate?.count.toString() || '0',
totalWithdrawn: Currency.Util.lovelacesToAda(
s.withdrawals_aggregate?.aggregate?.sum?.amount || '0'
),
transactionsCount:
s.transactions_aggregate?.aggregate?.count.toString() || '0'
}
};
10 changes: 9 additions & 1 deletion source/features/address/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
export interface IAddressSummary {
address: string;
finalBalance: string;
transactionsCount: string;
}

export interface IPaymentAddressSummary extends IAddressSummary {
finalBalance: string;
}

export interface IStakeAddressSummary extends IAddressSummary {
totalWithdrawals: string;
totalWithdrawn: string;
}
50 changes: 43 additions & 7 deletions source/features/address/ui/AddressSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,30 @@ import styles from './AddressSummary.module.scss';

export interface IAddressSummaryProps {
address: string;
finalBalance: string;
title: string;
transactionsCount: string;
}

const AddressSummary = (props: IAddressSummaryProps) => {
export interface IPaymentAddressSummaryProps extends IAddressSummaryProps {
finalBalance: string;
}

export interface IStakeAddressSummaryProps extends IAddressSummaryProps {
totalWithdrawn: string;
totalWithdrawals: string;
}

type AddressSummaryProps = IPaymentAddressSummaryProps | IStakeAddressSummaryProps

function isPaymentAddress (props: AddressSummaryProps): props is IPaymentAddressSummaryProps {
return (props as IPaymentAddressSummaryProps).finalBalance !== undefined;
}

function isStakeAddress (props: AddressSummaryProps): props is IStakeAddressSummaryProps {
return (props as IStakeAddressSummaryProps).totalWithdrawn !== undefined;
}

const AddressSummary = (props: AddressSummaryProps) => {
const { translate } = useI18nFeature().store;
return (
<div className={styles.addressSummaryContainer}>
Expand All @@ -32,12 +50,30 @@ const AddressSummary = (props: IAddressSummaryProps) => {
</div>
<div className={styles.infoValue}>{props.transactionsCount}</div>
</div>
<div className={styles.infoRow}>
<div className={styles.infoLabel}>
{translate('address.summaryBalanceLabel')}
{isPaymentAddress(props) && (
<div className={styles.infoRow}>
<div className={styles.infoLabel}>
{translate('address.summaryBalanceLabel')}
</div>
<div className={styles.infoValue}>{props.finalBalance} ADA</div>
</div>
<div className={styles.infoValue}>{props.finalBalance} ADA</div>
</div>
)}
{isStakeAddress(props) && (
<>
<div className={styles.infoRow}>
<div className={styles.infoLabel}>
{translate('withdrawals')}
</div>
<div className={styles.infoValue}>{props.totalWithdrawals}</div>
</div>
<div className={styles.infoRow}>
<div className={styles.infoLabel}>
{translate('address.totalWithdrawn')}
</div>
<div className={styles.infoValue}>{props.totalWithdrawn} ADA</div>
</div>
</>
)}
</div>
<div className={styles.qrcode}>
<QRCode
Expand Down
3 changes: 3 additions & 0 deletions source/features/blocks/api/BlockOverview.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ fragment BlockOverview on Block {
forgedAt
slotLeader {
description
stakePool {
hash
}
}
epochNo,
hash
Expand Down
13 changes: 10 additions & 3 deletions source/features/blocks/api/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ export const blockOverviewTransformer = (
} else {
epoch = b.epochNo;
}
const createdBy = b.slotLeader.stakePool?.hash !== undefined ?
shortenCreatedBy(b.slotLeader.stakePool.hash) :
formatSlotLeaderDescription(b.slotLeader.description)
return {
...b,
createdAt: b.forgedAt,
createdBy: formatCreatedBy(b.slotLeader.description),
createdBy,
epoch,
id: b.hash,
number: b.number || '-',
Expand Down Expand Up @@ -50,7 +53,11 @@ export const blockDetailsTransformer = (
.map(transactionDetailsTransformer),
});

function formatCreatedBy(value: IBlockOverview['createdBy']): string {
function shortenCreatedBy (createdBy: string) {
return createdBy.substring(0, 7)
}

function formatSlotLeaderDescription (value: IBlockOverview['createdBy']): string {
switch (value) {
case 'Genesis slot leader':
return 'Genesis';
Expand All @@ -61,7 +68,7 @@ function formatCreatedBy(value: IBlockOverview['createdBy']): string {
if (!Array.isArray(selection)) {
return '';
}
return selection[1].substring(0, 7);
return shortenCreatedBy(selection[1]);
}
}

Expand Down
8 changes: 6 additions & 2 deletions source/features/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"pageTitle": "$t(address.addressLabel) | $t(productTitle)",
"summaryAddressLabel": "$t(address.addressLabel)",
"summaryBalanceLabel": "Insgesamt",
"summaryTransactionsLabel": "Transaktionen"
"summaryTransactionsLabel": "Transaktionen",
"totalWithdrawn": "Insgesamt Ausbezahlt"
},
"block": {
"blocks": "Blöcke",
Expand Down Expand Up @@ -152,6 +153,8 @@
"transaction": {
"block": "Block",
"confirmations": "Konfirmationen",
"deposit": "Kaution",
"depositReclaim": "Kautionsrückforderung",
"epoch": "Epoche",
"fee": "Transaktionsgebühr",
"from": "Input-Adressen",
Expand All @@ -165,5 +168,6 @@
"totalOutput": "Output Insgesamt",
"transactionLabel": "Transaktion",
"transactionsLabel": "Transaktionen"
}
},
"withdrawals": "Abhebungen"
}
8 changes: 6 additions & 2 deletions source/features/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"pageTitle": "Address | $t(productTitle)",
"summaryAddressLabel": "Address",
"summaryBalanceLabel": "Final Balance",
"summaryTransactionsLabel": "Transactions"
"summaryTransactionsLabel": "Transactions",
"totalWithdrawn": "Total Withdrawn"
},
"block": {
"blocks": "Blocks",
Expand Down Expand Up @@ -153,6 +154,8 @@
"transaction": {
"block": "Block",
"confirmations": "Confirmations",
"deposit": "Deposit",
"depositReclaim": "Deposit Reclaim",
"epoch": "Epoch",
"fee": "Transaction Fee",
"from": "From addresses",
Expand All @@ -166,5 +169,6 @@
"totalOutput": "Total Output",
"transactionLabel": "Transaction",
"transactionsLabel": "Transactions"
}
},
"withdrawals": "Withdrawals"
}
8 changes: 6 additions & 2 deletions source/features/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"pageTitle": "アドレス | $t(productTitle)",
"summaryAddressLabel": "アドレス",
"summaryBalanceLabel": "最終残高",
"summaryTransactionsLabel": "トランザクション"
"summaryTransactionsLabel": "トランザクション",
"totalWithdrawn": "全額引き出し"
},
"block": {
"blocks": "ブロック",
Expand Down Expand Up @@ -152,6 +153,8 @@
"transaction": {
"block": "ブロック",
"confirmations": "確認",
"deposit": "デポジット",
"depositReclaim": "デポジットの返還",
"epoch": "エポック",
"fee": "トランザクション手数料",
"from": "送信元",
Expand All @@ -165,5 +168,6 @@
"totalOutput": "総アウトプット",
"transactionLabel": "トランザクション",
"transactionsLabel": "トランザクション"
}
},
"withdrawals": "引き出し"
}
28 changes: 20 additions & 8 deletions source/features/search/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,30 @@ import { GraphQLRequest } from '../../../lib/graphql/GraphQLRequest';
import {
SearchByIdQuery,
SearchByIdQueryVariables,
SearchForAddressQuery,
SearchForAddressQueryVariables,
SearchForBlockByNumberQuery,
SearchForBlockByNumberQueryVariables,
SearchForEpochByNumberQuery,
SearchForEpochByNumberQueryVariables,
SearchForPaymentAddressQuery,
SearchForPaymentAddressQueryVariables,
SearchForStakeAddressQuery,
SearchForStakeAddressQueryVariables
} from '../../../typings/graphql-schema';
import searchByIdQuery from './searchById.graphql';
import searchForAddressQuery from './searchForAddress.graphql';
import searchForBlockByNumberQuery from './searchForBlockByNumber.graphql';
import searchForEpochByNumberQuery from './searchForEpochByNumber.graphql';
import searchForPaymentAddressQuery from './searchForPaymentAddress.graphql';
import searchForStakeAddressQuery from './searchForStakeAddress.graphql';

export class SearchApi {
public searchForAddressQuery: GraphQLRequest<
SearchForAddressQuery,
SearchForAddressQueryVariables
public searchForPaymentAddressQuery: GraphQLRequest<
SearchForPaymentAddressQuery,
SearchForPaymentAddressQueryVariables
>;

public searchForStakeAddressQuery: GraphQLRequest<
SearchForStakeAddressQuery,
SearchForStakeAddressQueryVariables
>;

public searchByIdQuery: GraphQLRequest<
Expand All @@ -37,9 +45,13 @@ export class SearchApi {
>;

constructor(client: GraphQLClient) {
this.searchForAddressQuery = new GraphQLRequest(
this.searchForPaymentAddressQuery = new GraphQLRequest(
client,
searchForPaymentAddressQuery
);
this.searchForStakeAddressQuery = new GraphQLRequest(
client,
searchForAddressQuery
searchForStakeAddressQuery
);
this.searchByIdQuery = new GraphQLRequest(client, searchByIdQuery);
this.searchForBlockByNumberQuery = new GraphQLRequest(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
query searchForAddress(
query searchForPaymentAddress(
$address: String!
) {
utxos_aggregate (
Expand Down
38 changes: 38 additions & 0 deletions source/features/search/api/searchForStakeAddress.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#import "../../transactions/api/TransactionDetails.graphql"

query searchForStakeAddress(
$address: String!
) {
transactions_aggregate (
where: {
withdrawals: {
address: {
_eq: $address
}
}
}
) {
aggregate {
count
}
}
withdrawals {
transaction {
...TransactionDetails
}
}
withdrawals_aggregate (
where: {
address: {
_eq: $address
}
}
) {
aggregate {
count
sum {
amount
}
}
}
}
6 changes: 4 additions & 2 deletions source/features/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import { SearchStore } from './store';
* Defines the actions that are supported by this feature
*/
export class SearchActions {
public addressNotFound: Action<{ address: string }> = new Action();
public addressSearchRequested: Action<{ address: string }> = new Action();
public blockNumberSearchRequested: Action<{ number: number }> = new Action();
public epochNumberSearchRequested: Action<{ number: number }> = new Action();
public idSearchRequested: Action<{ id: string }> = new Action();
public unknownSearchRequested: Action<{ query: string }> = new Action();
public searchById: Action<{ id: string }> = new Action();
public searchForAddress: Action<{ address: string }> = new Action();
public searchForPaymentAddress: Action<{ address: string }> = new Action();
public searchForStakeAddress: Action<{ address: string }> = new Action();
public searchForBlockByNumber: Action<{ number: number }> = new Action();
public searchForEpochByNumber: Action<{ number: number }> = new Action();
public subscribeToEpoch: Action<{ number: number }> = new Action();
public unknownSearchRequested: Action<{ query: string }> = new Action();
public unsubscribeFromEpoch: Action<void> = new Action();
}

Expand Down
8 changes: 7 additions & 1 deletion source/features/search/specs/helpers/exampleAddressData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const exampleAddressData = {
export const examplePaymentAddressData = {
address: 'Ae2tdPwUPEZBZTsRj7nGvvWQDTkqD9KLpCPpuZvjA1roL7KLDDVgkPU5S8j',
finalBalance: '0',
transactions: [
Expand All @@ -25,3 +25,9 @@ export const exampleAddressData = {
],
transactionsCount: '2',
};

export const exampleStakeAddressData = {
address: 'stake1u8gu2vzsk2nc6hsphudhl3p6aum7nd59ajqjg9zp00uvxcqwsdray',
totalWithdrawn: '1563.774139',
transactionsCount: '1',
};
Loading

0 comments on commit 95cc20b

Please sign in to comment.