Skip to content

Commit

Permalink
fixed error handling for transaction page
Browse files Browse the repository at this point in the history
  • Loading branch information
baktun14 committed May 22, 2024
1 parent 35ff47e commit 4bac548
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 42 deletions.
7 changes: 5 additions & 2 deletions api/src/services/db/transactionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AkashBlock as Block, AkashMessage as Message } from "@shared/dbSchemas/
import { msgToJSON } from "@src/utils/protobuf";
import { QueryTypes } from "sequelize";
import { chainDb } from "@src/db/dbConnection";
import { ApiTransactionResponse } from "@src/types/transactions";

export async function getTransactions(limit: number) {
const _limit = Math.min(limit, 100);
Expand Down Expand Up @@ -41,7 +42,7 @@ export async function getTransactions(limit: number) {
}));
}

export async function getTransaction(hash: string) {
export async function getTransaction(hash: string): Promise<ApiTransactionResponse> {
const tx = await Transaction.findOne({
where: {
hash: hash
Expand All @@ -62,7 +63,9 @@ export async function getTransaction(hash: string) {
]
});

if (!tx) return null;
if (!tx) {
return null;
}

const messages = await Message.findAll({
where: {
Expand Down
11 changes: 1 addition & 10 deletions api/src/services/external/apiNodeService.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import fetch from "node-fetch";
import { getDeploymentRelatedMessages } from "../db/deploymentService";
import { averageBlockCountInAMonth } from "@src/utils/constants";
import { apiNodeUrl, averageBlockCountInAMonth, betaTypeVersion, betaTypeVersionMarket } from "@src/utils/constants";
import { coinToAsset } from "@src/utils/coin";
import { getTransactionByAddress } from "@src/services/db/transactionsService";
import axios from "axios";
import { Validator } from "@shared/dbSchemas/base";
import { Op } from "sequelize";
import { Deployment, Lease, Provider, ProviderAttribute } from "@shared/dbSchemas/akash";
import { cacheKeys, cacheResponse } from "@src/caching/helpers";
import { env } from "@src/utils/env";
import {
CosmosGovProposalResponse,
CosmosGovProposalsResponse,
Expand All @@ -31,15 +30,7 @@ import { CosmosDistributionParamsResponse } from "@src/types/rest/cosmosDistribu
import { CosmosDistributionValidatorsCommissionResponse } from "@src/types/rest/cosmosDistributionValidatorsCommissionResponse";
import { getProviderList } from "../db/providerStatusService";

const defaultNodeUrlMapping: { [key: string]: string } = {
mainnet: "https://api.akashnet.net:443",
sandbox: "https://api.sandbox-01.aksh.pw",
testnet: "https://api.testnet-02.aksh.pw"
};

const apiNodeUrl = env.RestApiNodeUrl ?? defaultNodeUrlMapping[env.Network] ?? defaultNodeUrlMapping.mainnet;
const betaTypeVersion = "v1beta3";
const betaTypeVersionMarket = "v1beta4";

export async function getChainStats() {
const result = await cacheResponse(
Expand Down
147 changes: 147 additions & 0 deletions api/src/types/rest/cosmosTransactionResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
export type RestCosmostTransactionResponse = {
tx: {
body: {
messages: {
"@type": string;
client_id: string;
header: {
"@type": string;
signed_header: {
header: {
version: {
block: string;
app: string;
};
chain_id: string;
height: string;
time: string;
last_block_id: {
hash: string;
part_set_header: {
total: number;
hash: string;
};
};
last_commit_hash: string;
data_hash: string;
validators_hash: string;
next_validators_hash: string;
consensus_hash: string;
app_hash: string;
last_results_hash: string;
evidence_hash: string;
proposer_address: string;
};
commit: {
height: string;
round: number;
block_id: {
hash: string;
part_set_header: {
total: number;
hash: string;
};
};
signatures: {
block_id_flag: string;
validator_address: string;
timestamp: string;
signature: string;
}[];
};
};
};
}[];
};
auth_info: {
signer_infos: [
{
public_key: {
"@type": string;
key: string;
};
mode_info: {
single: {
mode: string;
};
};
sequence: string;
}
];
fee: {
amount: [
{
denom: string;
amount: string;
}
];
gas_limit: string;
payer: string;
granter: string;
};
};
signatures: string[];
};
tx_response: {
height: string;
txhash: string;
codespace: string;
code: number;
data: string;
raw_log: string;
logs: {
msg_index: number;
log: string;
events: {
type: string;
attributes: {
key: string;
value: string;
}[];
}[];
}[];
info: string;
gas_wanted: string;
gas_used: string;
tx: {
type: string;
value: {
msg: {
type: string;
value: {
from_address: string;
to_address: string;
amount: {
denom: string;
amount: string;
}[];
};
}[];
fee: {
amount: {
denom: string;
amount: string;
}[];
gas: string;
};
signatures: {
pub_key: {
type: string;
value: string;
};
signature: string;
}[];
memo: string;
};
};
timestamp: string;
events: {
type: string;
attributes: {
key: string;
value: string;
index: boolean;
}[];
}[];
};
};
19 changes: 19 additions & 0 deletions api/src/types/transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export type ApiTransactionResponse = {
height: number | string;
datetime: Date;
hash: string;
multisigThreshold?: number;
signers?: string[];
isSuccess: boolean;
error: string | null;
gasUsed: number;
gasWanted: number;
fee: number;
memo: string;
messages: {
id: string;
type: string;
data: any;
relatedDeploymentId: string | null;
}[];
};
10 changes: 10 additions & 0 deletions api/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ export const openApiExampleAddress = "akash13265twfqejnma6cc93rw5dxk4cldyz2zyy8c
export const openApiExampleProviderAddress = "akash18ga02jzaq8cw52anyhzkwta5wygufgu6zsz6xc";
export const openApiExampleTransactionHash = "A19F1950D97E576F0D7B591D71A8D0366AA8BA0A7F3DA76F44769188644BE9EB";
export const openApiExampleValidatorAddress = "akashvaloper14mt78hz73d9tdwpdvkd59ne9509kxw8yj7qy8f";

export const defaultNodeUrlMapping: { [key: string]: string } = {
mainnet: "https://api.akashnet.net:443",
sandbox: "https://api.sandbox-01.aksh.pw",
testnet: "https://api.testnet-02.aksh.pw"
};

export const apiNodeUrl = env.RestApiNodeUrl ?? defaultNodeUrlMapping[env.Network] ?? defaultNodeUrlMapping.mainnet;
export const betaTypeVersion = "v1beta3";
export const betaTypeVersionMarket = "v1beta4";
5 changes: 3 additions & 2 deletions deploy-web/src/context/WalletProvider/WalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useRef } from "react";
import { useState, useEffect } from "react";
import { SigningStargateClient } from "@cosmjs/stargate";
import { uAktDenom } from "@src/utils/constants";
import { STATS_APP_URL, uAktDenom } from "@src/utils/constants";
import { EncodeObject } from "@cosmjs/proto-signing";
import { TransactionModal } from "@src/components/layout/TransactionModal";
import { event } from "nextjs-google-analytics";
Expand Down Expand Up @@ -325,8 +325,9 @@ export function useWallet() {

const TransactionSnackbarContent = ({ snackMessage, transactionHash }) => {
const selectedNetwork = useSelectedNetwork();
const txUrl = transactionHash && `https://stats.akash.network/transactions/${transactionHash}?network=${selectedNetwork.id}`;
const txUrl = transactionHash && `${STATS_APP_URL}/transactions/${transactionHash}?network=${selectedNetwork.id}`;

console.log(txUrl);
return (
<>
{snackMessage}
Expand Down
9 changes: 9 additions & 0 deletions deploy-web/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export enum RouteStepKeys {
const productionMainnetApiUrl = "https://api.cloudmos.io";
const productionTestnetApiUrl = "https://api-testnet.cloudmos.io";
const productionSandboxApiUrl = "https://api-sandbox.cloudmos.io";
const productionStatsAppUrl = "https://stats.akash.network";
const productionHostnames = ["deploy.cloudmos.io", "console.akash.network", "staging-console.akash.network", "beta.cloudmos.io"];

export const isProd = process.env.NODE_ENV === "production";
export const isMaintenanceMode = process.env.MAINTENANCE_MODE === "true";
export const BASE_API_MAINNET_URL = getApiMainnetUrl();
export const BASE_API_TESTNET_URL = getApiTestnetUrl();
export const BASE_API_SANDBOX_URL = getApiSandboxUrl();
export const STATS_APP_URL = getStatsAppUrl();

export const BASE_API_URL = getApiUrl();

Expand Down Expand Up @@ -100,6 +102,13 @@ function getApiUrl() {
return "http://localhost:3080";
}

function getStatsAppUrl() {
if (process.env.STATS_APP_URL) return process.env.STATS_APP_URL;
if (typeof window === "undefined") return "http://localhost:3001";
if (productionHostnames.includes(window.location?.hostname)) return productionStatsAppUrl;
return "http://localhost:3001";
}

function getProviderProxyHttpUrl() {
if (typeof window === "undefined") return "http://localhost:3040";
if (window.location?.hostname === "deploybeta.cloudmos.io") return "https://deployproxybeta.cloudmos.io";
Expand Down
14 changes: 9 additions & 5 deletions stats-web/src/app/errors.tsx → stats-web/src/app/error.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"use client"; // Error components must be Client Components

import PageContainer from "@/components/PageContainer";
import { Title } from "@/components/Title";
import { Button } from "@/components/ui/button";
import { useEffect } from "react";

export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) {
Expand All @@ -9,16 +12,17 @@ export default function Error({ error, reset }: { error: Error & { digest?: stri
}, [error]);

return (
<div>
<h2>Something went wrong!</h2>
<button
<PageContainer>
<Title>Something went wrong!</Title>
<Button
className="my-4"
onClick={
// Attempt to recover by trying to re-render the segment
() => reset()
}
>
Try again
</button>
</div>
</Button>
</PageContainer>
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"use client"; // Error components must be Client Components

import PageContainer from "@/components/PageContainer";
import { Title } from "@/components/Title";
import { Button } from "@/components/ui/button";
import { useEffect } from "react";

export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) {
Expand All @@ -9,16 +12,17 @@ export default function Error({ error, reset }: { error: Error & { digest?: stri
}, [error]);

return (
<div>
<h2>Something went wrong!</h2>
<button
<PageContainer>
<Title>Something went wrong!</Title>
<Button
className="my-4"
onClick={
// Attempt to recover by trying to re-render the segment
() => reset()
}
>
Try again
</button>
</div>
</Button>
</PageContainer>
);
}
Loading

0 comments on commit 4bac548

Please sign in to comment.