Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(activity): red status for failed transactions #641

Merged
merged 1 commit into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/extension/src/ui/components/ErrorBoundaryFallback.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { FC } from "react"
import styled from "styled-components"

import { ReportGmailerrorredIcon } from "./Icons/MuiIcons"

const Container = styled.div`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;

& > svg {
color: red;
font-size: 64px;
margin-bottom: 16px;
}
`

interface ErrorBoundaryFallbackProps {
title: string
}

export const ErrorBoundaryFallback: FC<ErrorBoundaryFallbackProps> = ({
title,
}) => (
<Container>
<ReportGmailerrorredIcon />
<h3>{title}</h3>
</Container>
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from "styled-components"

import { useAppState } from "../../app.state"
import { ErrorBoundary } from "../../components/ErrorBoundary"
import { ReportGmailerrorredIcon } from "../../components/Icons/MuiIcons"
import { ErrorBoundaryFallback } from "../../components/ErrorBoundaryFallback"
import { Spinner } from "../../components/Spinner"
import { formatDateTime } from "../../services/dates"
import { openVoyagerTransaction } from "../../services/voyager.service"
Expand Down Expand Up @@ -45,10 +45,11 @@ const Activity: FC<AccountActivityProps> = ({ account }) => {
<Fragment key={dateLabel}>
<SectionHeader>{dateLabel}</SectionHeader>
<TransactionsWrapper>
{transactions.map(({ hash, date, meta }) => (
{transactions.map(({ hash, date, meta, isRejected }) => (
<TransactionItem
key={hash}
hash={hash}
status={isRejected ? "red" : undefined}
meta={{ subTitle: formatDateTime(date), ...meta }}
onClick={() => openVoyagerTransaction(hash, network)}
/>
Expand All @@ -60,38 +61,18 @@ const Activity: FC<AccountActivityProps> = ({ account }) => {
)
}

const ActivityError: FC = () => {
return (
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
}}
export const AccountActivity: FC<AccountActivityProps> = ({ account }) => (
<Container>
<Header>Activity</Header>
<PendingTransactions accountAddress={account.address} />
<ErrorBoundary
fallback={
<ErrorBoundaryFallback title="Seems like Voyager API is down..." />
}
>
<ReportGmailerrorredIcon
style={{
color: "red",
fontSize: "64px",
marginBottom: "16px",
}}
/>
<h3>Seems like Voyager API is down...</h3>
</div>
)
}

export const AccountActivity: FC<AccountActivityProps> = ({ account }) => {
return (
<Container>
<Header>Activity</Header>
<PendingTransactions accountAddress={account.address} />
<ErrorBoundary fallback={<ActivityError />}>
<Suspense fallback={<Spinner size={64} style={{ marginTop: 40 }} />}>
<Activity account={account} />
</Suspense>
</ErrorBoundary>
</Container>
)
}
<Suspense fallback={<Spinner size={64} style={{ marginTop: 40 }} />}>
<Activity account={account} />
</Suspense>
</ErrorBoundary>
</Container>
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface ActivityTransaction {
hash: string
date: Date
meta?: TransactionMeta
isRejected?: boolean
}

export type DailyActivity = Record<string, ActivityTransaction[]>
Expand All @@ -18,8 +19,9 @@ export function useActivity(address: string): DailyActivity {
if (status !== "RECEIVED") {
const date = new Date(timestamp * 1000)
const dateLabel = formatDate(date)
const isRejected = status === "REJECTED"
activity[dateLabel] ||= []
activity[dateLabel].push({ hash, date, meta })
activity[dateLabel].push({ hash, date, meta, isRejected })
}
}
return activity
Expand Down
26 changes: 4 additions & 22 deletions packages/extension/src/ui/features/accountNfts/AccountNfts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useNavigate } from "react-router-dom"
import styled from "styled-components"

import { ErrorBoundary } from "../../components/ErrorBoundary"
import { ReportGmailerrorredIcon } from "../../components/Icons/MuiIcons"
import { ErrorBoundaryFallback } from "../../components/ErrorBoundaryFallback"
import { Spinner } from "../../components/Spinner"
import { P } from "../../components/Typography"
import { routes } from "../../routes"
Expand Down Expand Up @@ -85,39 +85,21 @@ const Nfts: FC<AccountNftsProps> = ({ account }) => {
)
}

const NftsError: FC<AccountNftsProps> = ({ account }) => {
const NftsFallback: FC<AccountNftsProps> = ({ account }) => {
// this is needed to keep swr mounted so it can retry the request
useNfts(account.address, {
suspense: false,
errorRetryInterval: 30e3 /* 30 seconds */,
})

return (
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
}}
>
<ReportGmailerrorredIcon
style={{
color: "red",
fontSize: "64px",
marginBottom: "16px",
}}
/>
<h3>Seems like Play Oasis API is down...</h3>
</div>
)
return <ErrorBoundaryFallback title="Seems like Play Oasis API is down..." />
}

export const AccountNfts: FC<AccountNftsProps> = ({ account }) => {
return (
<Container>
<Header>Collectibles</Header>
<ErrorBoundary fallback={<NftsError account={account} />}>
<ErrorBoundary fallback={<NftsFallback account={account} />}>
<Suspense fallback={<Spinner size={64} style={{ marginTop: 40 }} />}>
<Nfts account={account} />
</Suspense>
Expand Down
4 changes: 2 additions & 2 deletions packages/extension/src/ui/services/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ export const updateTransactionFee = async (
}

export const startSession = async (password: string): Promise<void> => {
const encMsg = await encrypt(password)
const body = await encrypt(password)

sendMessage({ type: "START_SESSION", data: { secure: true, body: encMsg } })
sendMessage({ type: "START_SESSION", data: { secure: true, body } })

const succeeded = await Promise.race([
waitForMessage("START_SESSION_RES").then(() => true),
Expand Down