Skip to content

Commit

Permalink
Merge pull request #432 from terra-money/staging
Browse files Browse the repository at this point in the history
7.2.9
  • Loading branch information
terran6 authored Jun 13, 2023
2 parents 40d26a5 + 859d4e1 commit 88165c7
Show file tree
Hide file tree
Showing 38 changed files with 462 additions and 200 deletions.
54 changes: 38 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"@mui/icons-material": "^5.8.0",
"@mui/material": "^5.9.1",
"@sentry/react": "^7.53.1",
"@terra-money/feather.js": "^1.0.4",
"@terra-money/feather.js": "^1.0.6",
"@terra-money/ledger-station-js": "^1.3.7",
"@terra-money/log-finder-ruleset": "^3.0.0",
"@terra-money/terra-utils": "^1.0.9",
"@terra-money/terra.js": "^3.1.7",
"@terra-money/terra.js": "^3.1.9",
"@terra-money/terra.proto": "^2.0.0",
"@terra-money/use-wallet": "4.0.0-beta.3",
"@terra-money/wallet-controller": "4.0.0-beta.3",
Expand Down
3 changes: 2 additions & 1 deletion src/app/InitBankBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const InitBankBalance = ({ children }: PropsWithChildren<{}>) => {
)

native.list.forEach(({ id }) => {
const [chain, denom] = id.split(":")
const [chain, ...denomData] = id.split(":")
const denom = denomData.join(":")
if (
!bankBalance.find(
(balance) => balance.denom === denom && balance.chain === chain
Expand Down
25 changes: 25 additions & 0 deletions src/components/display/DateTimeRenderer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ToNow } from "."

const validFormats = ["relative", "localestring"] as const

interface Props {
children: string | Date
format: typeof validFormats[number]
update?: boolean
}

const DateTimeRenderer = ({ children: timestamp, format, update }: Props) => {
const dateString =
typeof timestamp === "string" ? timestamp : timestamp.toISOString()

switch (format) {
case "relative":
return <ToNow update={update}>{new Date(dateString)}</ToNow>
case "localestring":
return <span>{new Date(dateString).toLocaleString()}</span>
default:
return <span>{dateString}</span>
}
}

export default DateTimeRenderer
1 change: 1 addition & 0 deletions src/components/display/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export * from "./List"
export { default as Tag } from "./Tag"
export { default as ToNow } from "./ToNow"
export { default as Tooltip } from "./Tooltip"
export { default as DateTimeRenderer } from "./DateTimeRenderer"
export * from "./Tooltip"
7 changes: 4 additions & 3 deletions src/components/general/CopyIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { useState } from "react"
interface Props {
text: string
className?: string
size?: number
}
const CopyIcon = ({ text, className }: Props) => {
const CopyIcon = ({ text, className, size }: Props) => {
const [copied, setCopied] = useState(false)

return (
Expand All @@ -19,9 +20,9 @@ const CopyIcon = ({ text, className }: Props) => {
}}
>
{copied ? (
<Check style={{ fontSize: 18 }} />
<Check style={{ fontSize: size ?? 18 }} />
) : (
<ContentCopy style={{ fontSize: 18 }} />
<ContentCopy style={{ fontSize: size ?? 18 }} />
)}
</button>
)
Expand Down
1 change: 0 additions & 1 deletion src/components/token/TokenIcon.module.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.icon {
border-radius: 50%;
background-color: var(--button-default-bg);
}

.inherit {
Expand Down
5 changes: 2 additions & 3 deletions src/components/token/TokenIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ const TokenIcon = ({ token, icon, size, ...rest }: Props) => {
size === "inherit"
? undefined
: {
width: size ?? 34,
height: size ?? 34,
style: { padding: (size ?? 34) / 3.5 },
width: size ?? 24,
height: size ?? 24,
}

const attrs = { ...rest, ...sizes, src, className: cx(styles.icon, size) }
Expand Down
14 changes: 11 additions & 3 deletions src/data/token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export const useNativeDenoms = () => {

let decimals = DEFAULT_NATIVE_DECIMALS

function readNativeDenom(denom: Denom, chainID?: string): TokenItem {
function readNativeDenom(
denom: Denom,
chainID?: string
): TokenItem & { isNonWhitelisted?: boolean } {
let tokenType = ""

if (denom.startsWith("ibc/")) {
Expand All @@ -114,8 +117,12 @@ export const useNativeDenoms = () => {
break

case "factory": {
// TODO - lookup whitelist for factory tokens.
fixedDenom = "..."
const factoryParts = denom.split(/[/:]/)
let tokenAddress = ""
if (factoryParts.length >= 2) {
tokenAddress = factoryParts.slice(2).join(" ")
}
fixedDenom = tokenAddress
break
}

Expand Down Expand Up @@ -176,6 +183,7 @@ export const useNativeDenoms = () => {
? factoryIcon
: "https://assets.terra.money/icon/svg/Terra.svg",
decimals,
isNonWhitelisted: true,
}
)
}
Expand Down
8 changes: 6 additions & 2 deletions src/pages/gov/ProposalDeposits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useProposal } from "data/queries/gov"
import { useDeposits, useDepositParams } from "data/queries/gov"
import { Card } from "components/layout"
import { Read } from "components/token"
import { ToNow } from "components/display"
import { DateTimeRenderer } from "components/display"
import Orb from "./components/Orb"
import styles from "./ProposalDeposits.module.scss"
import { useNetwork } from "data/wallet"
Expand Down Expand Up @@ -55,7 +55,11 @@ const ProposalDeposits = ({ id, chain, card }: Props) => {
},
{
title: t("Deposit end time"),
content: <ToNow>{new Date(deposit_end_time)}</ToNow>,
content: (
<DateTimeRenderer format={"localestring"}>
{deposit_end_time}
</DateTimeRenderer>
),
},
]

Expand Down
7 changes: 5 additions & 2 deletions src/pages/gov/ProposalHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTranslation } from "react-i18next"
import { ProposalResult, useParseProposalType } from "data/queries/gov"
import { useProposalStatusItem } from "data/queries/gov"
import { ToNow } from "components/display"
import { DateTimeRenderer } from "components/display"
import styles from "./ProposalHeader.module.scss"
import { useNetwork } from "data/wallet"

Expand Down Expand Up @@ -34,7 +34,10 @@ const ProposalHeader = ({

<h1 className={styles.title}>{title}</h1>
<p className={styles.date}>
{t("Submitted")} <ToNow>{new Date(submit_time)}</ToNow>
{t("Submitted")}{" "}
<DateTimeRenderer format={"localestring"}>
{submit_time}
</DateTimeRenderer>
</p>
</header>
)
Expand Down
6 changes: 4 additions & 2 deletions src/pages/gov/ProposalVotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useStakingPool } from "data/queries/staking"
import { Col, Row, Card, Grid } from "components/layout"
import { Fetching, Empty } from "components/feedback"
import { Read } from "components/token"
import { ToNow } from "components/display"
import { DateTimeRenderer } from "components/display"
import VoteProgress from "./components/VoteProgress"
import styles from "./ProposalVotes.module.scss"

Expand Down Expand Up @@ -121,7 +121,9 @@ const ProposalVotes = ({

<p className={styles.end}>
{new Date(voting_end_time) > new Date() ? t("Ends") : t("Ended")}{" "}
<ToNow>{new Date(voting_end_time)}</ToNow>
<DateTimeRenderer format={"localestring"}>
{voting_end_time}
</DateTimeRenderer>
</p>
</Grid>
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/gov/components/VoteProgress.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

.label,
.line {
transform: translate(-50%, 0);
transform: translate(var(--x-pos), 0);
}
}

Expand Down
38 changes: 33 additions & 5 deletions src/pages/gov/components/VoteProgress.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
import { PropsWithChildren } from "react"
import classNames from "classnames"
import { Flex } from "components/layout"
import { useLayoutEffect, PropsWithChildren, useRef, useState } from "react"
import styles from "./VoteProgress.module.scss"
import { Flex } from "components/layout"
import classNames from "classnames"

const Flag = ({ left, children }: PropsWithChildren<{ left: string }>) => {
const ref = useRef<HTMLDivElement>(null)
const [width, setWidth] = useState(0)

useLayoutEffect(() => {
if (ref.current) setWidth(ref.current.offsetWidth)
}, [ref.current?.offsetWidth])

let maxTranslate = 45
switch (children) {
case "Pass Threshold":
maxTranslate = 45
break
case "Vote Threshold":
maxTranslate = 45.3
break
case "Quorum":
maxTranslate = 23.9
break
}

const translateStyle = {
"--x-pos":
(parseFloat(left) / 100) * width < maxTranslate
? `-${(parseFloat(left) / 100) * width}px`
: "-50%",
} as React.CSSProperties
return (
<div className={styles.flag} style={{ left }}>
<span className={styles.label}>{children}</span>
<div ref={ref} className={styles.flag} style={{ left }}>
<span className={styles.label} style={translateStyle}>
{children}
</span>
<span className={styles.line} />
</div>
)
Expand Down
6 changes: 4 additions & 2 deletions src/pages/history/HistoryItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Fragment } from "react"
import { useTranslation } from "react-i18next"
import { FinderLink } from "components/general"
import { Card } from "components/layout"
import { Dl, ToNow } from "components/display"
import { Dl, DateTimeRenderer } from "components/display"
import { ReadMultiple } from "components/token"
import HistoryMessage from "./HistoryMessage"
import styles from "./HistoryItem.module.scss"
Expand Down Expand Up @@ -73,7 +73,9 @@ const HistoryItem = ({
</p>
<p className={styles.time}>
<DateRangeIcon />
<ToNow>{new Date(timestamp)}</ToNow>
<DateTimeRenderer format={"localestring"}>
{timestamp}
</DateTimeRenderer>
</p>
</header>

Expand Down
Loading

0 comments on commit 88165c7

Please sign in to comment.