-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
245 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { reportError } from 'errors/errorMonitoring'; | ||
import { ComponentWithChildrenProps } from 'lib/shared/props'; | ||
import React, { Component, ReactNode } from 'react'; | ||
|
||
interface ErrorBoundaryProps extends ComponentWithChildrenProps { | ||
fallback?: ReactNode; | ||
} | ||
|
||
interface State { | ||
hasError: boolean; | ||
} | ||
|
||
export class ErrorBoundary extends Component<ErrorBoundaryProps, State> { | ||
constructor(props: ErrorBoundaryProps) { | ||
super(props); | ||
this.state = { | ||
hasError: false, | ||
}; | ||
} | ||
|
||
static getDerivedStateFromError(_: Error): State { | ||
return { hasError: true }; | ||
} | ||
|
||
componentDidCatch(error: Error): void { | ||
reportError(error) | ||
} | ||
|
||
render(): React.ReactNode { | ||
if (this.state.hasError) { | ||
return this.props.fallback || null | ||
} | ||
|
||
return this.props.children | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ComponentProps, ReactNode } from 'react' | ||
import styled from 'styled-components' | ||
import { HSLA } from 'lib/ui/colors/HSLA' | ||
import { Text } from 'lib/ui/Text' | ||
|
||
type Props = ComponentProps<typeof Text> & { | ||
color: HSLA | ||
children: ReactNode | ||
} | ||
|
||
const Container = styled(Text) <{ $color: HSLA }>` | ||
padding: 4px 8px; | ||
border-radius: 8px; | ||
color: ${({ $color }) => $color.toCssValue()}; | ||
background: ${({ $color }) => | ||
$color.getVariant({ a: () => 0.14 }).toCssValue()}; | ||
` | ||
|
||
export const Tag = ({ color, children, ...rest }: Props) => { | ||
return ( | ||
<Container as="span" $color={color} {...rest}> | ||
{children} | ||
</Container> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { demicrofy, formatAmount } from "@terra-money/apps/libs/formatting" | ||
import { isDenom } from "@terra.kitchen/utils" | ||
import { AssetType } from "chain" | ||
import { useAssetInfoQuery } from "chain/queries/useAssetInfoQuery" | ||
import { Spinner } from "lib/ui/Spinner" | ||
import { Text } from "lib/ui/Text" | ||
|
||
interface TxAssetProps { | ||
id: string | ||
amount: string | ||
} | ||
|
||
export const TxAsset = ({ id, amount }: TxAssetProps) => { | ||
const type: AssetType = isDenom(id) ? 'native' : 'cw20' | ||
|
||
const { data, isLoading } = useAssetInfoQuery({ id, type }) | ||
|
||
if (data) { | ||
const { symbol, decimals } = data | ||
return ( | ||
<Text weight="semibold" color="regular"> | ||
{formatAmount(demicrofy(amount, decimals))} {symbol} | ||
</Text> | ||
) | ||
} | ||
|
||
if (isLoading) { | ||
return <Spinner /> | ||
} | ||
|
||
return <>🤷♂️</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { capitalizeFirstLetter, truncateAddress } from "@terra-money/apps/utils" | ||
import { AccAddress, Coin, Coins, } from "@terra-money/terra.js" | ||
import { useWallet } from "@terra-money/wallet-provider" | ||
import { isDenom } from "@terra.kitchen/utils" | ||
import { ExternalLink } from "lib/navigation/Link/ExternalLink" | ||
import { ShyTextButton } from "lib/ui/buttons/ShyTextButton" | ||
import { HStack } from "lib/ui/Stack" | ||
import { Text } from "lib/ui/Text" | ||
import { ReactNode } from "react" | ||
import { TxAsset } from "./TxAsset" | ||
|
||
interface TxMessageProps { | ||
text: string | ||
targetAddress: string | ||
} | ||
|
||
const validateTokens = (tokens: any) => { | ||
const validate = ({ denom }: Coin) => | ||
isDenom(denom) || AccAddress.validate(denom) | ||
|
||
try { | ||
const coins = new Coins(tokens) | ||
return coins.toArray().every(validate) | ||
} catch { | ||
return false | ||
} | ||
} | ||
|
||
export const TxMessage = ({ text, targetAddress }: TxMessageProps) => { | ||
const { network } = useWallet() | ||
|
||
const parse = (word: string, index: number): ReactNode => { | ||
if (!word) return null | ||
if (word === targetAddress) return 'treasury' | ||
|
||
if (word.endsWith(",")) return <>{parse(word.slice(0, -1), index)},</> | ||
|
||
if (validateTokens(word)) { | ||
const list = new Coins(word).toArray() | ||
|
||
return ( | ||
<span style={{ color: 'purple' }}> | ||
{list.length > 1 ? 'multiple tokens' : list.map((coin, index) => { | ||
// todo: style address | ||
const denom = coin.toData().denom | ||
const [amount] = word.split(denom) | ||
return <TxAsset amount={amount} id={denom} /> | ||
})} | ||
|
||
</span> | ||
) | ||
} | ||
|
||
if (AccAddress.validate(word)) { | ||
return ( | ||
<ExternalLink to={`https://terrasco.pe/${network.name}/address/${word}`}> | ||
<ShyTextButton text={truncateAddress(word)} as="div" /> | ||
</ExternalLink> | ||
) | ||
} | ||
|
||
if (index === 0) { | ||
return capitalizeFirstLetter(word) | ||
} | ||
|
||
return <span>{word}</span> | ||
} | ||
return ( | ||
<Text as="div" style={{ textAlign: 'start' }} color="supporting"> | ||
<HStack alignItems="center" gap={4}> | ||
{text.split(' ').map((word, index) => { | ||
const parsed = parse(word, index) | ||
|
||
return <span key={index}>{parsed}</span> | ||
})} | ||
</HStack> | ||
</Text> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters