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

Feature/ux improvement #98

Merged
merged 3 commits into from
May 11, 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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"dependencies": {
"@apollo/client": "^3.2.4",
"@terra-dev/wallet-types": "^3.7.0",
"@terra-money/log-finder": "^1.1.6",
"@terra-money/log-finder-ruleset": "^3.0.0",
"@terra-money/react-base-components": "^2.0.0",
"@terra-money/terra.js": "^3.0.4",
"@terra-money/wallet-provider": "^3.7.1",
"@testing-library/jest-dom": "^5.11.4",
Expand Down
2 changes: 1 addition & 1 deletion src/components/LatestBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Indicator = styled.div<{ status?: "success" | "error" }>`
`

const Label = styled.div`
font-family: OpenSans;
font-family: "Open Sans", arial, sans-serif;
font-size: 14px;
font-weight: normal;
font-stretch: normal;
Expand Down
11 changes: 6 additions & 5 deletions src/components/Warning.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
.component {
@include flex;
flex-direction: column;
width: 100%;
width: calc(100% - 32px);
max-width: 490px;
border-radius: 20px;
font-family: $font-family-swap;
background-color: white;
margin: 0 auto;
}

.title {
margin-top: 30px;
font-family: OpenSans;
font-family: "Open Sans", arial, sans-serif;
font-size: 20px;
font-weight: bold;
font-stretch: normal;
Expand All @@ -27,7 +28,7 @@
.spread {
margin-top: 30px;
margin-bottom: 10px;
font-family: OpenSans;
font-family: "Open Sans", arial, sans-serif;
font-size: 18px;
font-weight: bold;
font-stretch: normal;
Expand All @@ -40,7 +41,7 @@

.message {
margin-bottom: 30px;
font-family: OpenSans;
font-family: "Open Sans", arial, sans-serif;
font-size: 18px;
font-weight: normal;
font-stretch: normal;
Expand All @@ -57,7 +58,7 @@
margin-bottom: 30px;
padding: 14px 65px;
border-radius: 10px;
font-family: OpenSans;
font-family: "Open Sans", arial, sans-serif;
font-size: 16px;
font-weight: bold;
font-stretch: normal;
Expand Down
36 changes: 7 additions & 29 deletions src/forms/ConfirmDetails.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,29 @@
@import "src/styles/variables.module";

.item {
border-top: 1px solid #b5b5b5;
padding-top: 10px;
padding-bottom: 13px;
display: block;
}

.item:last-child {
border-bottom: 1px solid #b5b5b5;
.item:first-child {
border-top: 1px solid #b5b5b5;
margin-top: 36px;
padding-top: 4px;
}

.article {
@include flex;
align-items: flex-start;
align-items: center;
}

.title,
.content {
flex: 1;
display: flex;
margin-top: 6px;
}

.title {
color: #5c5c5c;
font-size: 14px;
font-weight: 600;
padding-top: 5px;
}

.content {
Expand All @@ -44,7 +41,7 @@
flex: 3;
justify-content: flex-end;
color: #4360e5;
font-size: 16px;
font-size: 14px;
line-height: 34px;
text-align: right;
white-space: pre-line;
Expand All @@ -56,38 +53,19 @@
justify-content: flex-end;
}

.title1,
.content1 {
}

.title1 {
color: #5c5c5c;
font-size: 14px;
font-weight: 600;
}

.content1 {
color: #5c5c5c;
font-size: 22px;
font-weight: bold;
text-align: right;
white-space: pre-line;
word-break: break-all;
align-self: flex-end;
}

.title2 {
margin-top: 6px;
color: #5c5c5c;
font-size: 14px;
font-weight: normal;
align-self: flex-end;
}

.content2 {
color: #5c5c5c;
font-size: 14px;
line-height: 28px;
font-weight: 600;
text-align: right;
white-space: pre-line;
Expand Down
14 changes: 6 additions & 8 deletions src/forms/ConfirmDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ const displayStr = (content: any, index: number) => {
const ConfirmDetails = ({ contents, result }: Props) =>
!contents ? null : (
<ul className={styles.list}>
{contents.map((contentArray, index) => (
<li className={styles.item} key={index}>
{contentArray.map(({ title, content }, index) => (
<article className={styles.article}>
<h2 className={index === 0 ? styles.title : styles.title2}>
{title}
</h2>
{displayStr(content, index)}
{contents.map((contentArray, i) => (
<li className={styles.item} key={i}>
{contentArray.map(({ title, content }, j) => (
<article key={`${i}-${j}`} className={styles.article}>
<b className={styles.title}>{title}</b>
{displayStr(content, j)}
</article>
))}
</li>
Expand Down
57 changes: 54 additions & 3 deletions src/forms/Result.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from "react"
import { useEffect, useRef, useState } from "react"
import classNames from "classnames/bind"

import { MAX_TX_POLLING_RETRY, TX_POLLING_INTERVAL } from "constants/constants"
Expand All @@ -22,6 +22,16 @@ import {
import axios from "rest/request"
import { AxiosError } from "axios"

import { useMemo } from "react"
import {
createActionRuleSet,
createLogMatcherForActions,
getTxCanonicalMsgs,
} from "@terra-money/log-finder-ruleset"
import { SwapTxInfo as ISwapTxInfo } from "types/swapTx"
import { TxInfo } from "@terra-money/terra.js"
import { TxDescription } from "@terra-money/react-base-components"
import { useLCDClient } from "@terra-money/wallet-provider"
export interface ResultProps {
response?: TxResult
error?:
Expand All @@ -44,10 +54,22 @@ enum STATUS {
}

const Result = ({ response, error, onFailure, parserKey }: ResultProps) => {
const network = useNetwork()
const { config } = useLCDClient()

const txHash = response?.result?.txhash ?? ""
const raw_log = response?.result?.raw_log ?? ""
/* polling */
const [txInfo, setTxInfo] = useState<SwapTxInfo>()
const [txInfo, setTxInfo] = useState<ISwapTxInfo>()

const matchedMsg = useMemo(() => {
if (!txInfo || !network?.name) {
return undefined
}
const actionRules = createActionRuleSet(network?.name)
const logMatcher = createLogMatcherForActions(actionRules)
return getTxCanonicalMsgs(txInfo as unknown as TxInfo, logMatcher)
}, [network, txInfo])

const [status, setStatus] = useState<STATUS>(STATUS.LOADING)
const { fcd } = useNetwork()
Expand Down Expand Up @@ -119,7 +141,36 @@ const Result = ({ response, error, onFailure, parserKey }: ResultProps) => {

const content = {
[STATUS.SUCCESS]: txInfo && (
<SwapTxInfo txInfo={txInfo} parserKey={parserKey} />
<>
<div style={{ textAlign: "center", marginTop: 16 }}>
<div>
{response?.msgs?.map((_, index) => {
const msgInfo = matchedMsg?.[index]

return (
<>
{msgInfo
?.filter((msg) => !!msg?.transformed?.canonicalMsg)
.map((msg) =>
msg?.transformed?.canonicalMsg?.map((str) => (
<div style={{ color: "#5c5c5c", fontSize: 18 }}>
<TxDescription
network={{ ...config, name: network?.name }}
config={{ printCoins: 3 }}
>
{str}
</TxDescription>
</div>
))
)}
<br />
</>
)
})}
</div>
</div>
<SwapTxInfo txInfo={txInfo} parserKey={parserKey} />
</>
),
[STATUS.LOADING]: (
<div>
Expand Down
16 changes: 7 additions & 9 deletions src/forms/SwapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import useAutoRouter from "rest/useAutoRouter"
import { useLCDClient } from "layouts/WalletConnectProvider"
import { useContractsAddress } from "hooks/useContractsAddress"
import WarningModal from "components/Warning"
import { AxiosError } from "axios"

enum Key {
value1 = "value1",
Expand Down Expand Up @@ -353,9 +352,9 @@ const SwapForm = ({ type, tabs }: { type: Type; tabs: TabViewProps }) => {
const simulationContents = useMemo(() => {
if (
!(
formData[Key.value1] &&
Number(formData[Key.value1]) &&
formData[Key.symbol1] &&
formData[Key.value2] &&
Number(formData[Key.value2]) &&
(type !== Type.WITHDRAW ? formData[Key.symbol2] : true)
)
) {
Expand Down Expand Up @@ -849,11 +848,11 @@ const SwapForm = ({ type, tabs }: { type: Type; tabs: TabViewProps }) => {
try {
settingsModal.close()

if (!profitableQuery?.msg) {
return
}
let msgs: any = {}
if (type === Type.SWAP) {
if (!profitableQuery?.msg) {
return
}
msgs = getMsgs(profitableQuery?.msg, {
amount: `${value1}`,
minimumReceived: profitableQuery
Expand Down Expand Up @@ -920,8 +919,7 @@ const SwapForm = ({ type, tabs }: { type: Type; tabs: TabViewProps }) => {
return
}
} catch (error) {
console.error((error as AxiosError).message)

console.error(error)
setResult(error as any)
}
},
Expand Down Expand Up @@ -1173,7 +1171,7 @@ const SwapForm = ({ type, tabs }: { type: Type; tabs: TabViewProps }) => {
focused={selectToken2.isOpen}
isLoading={
type === Type.SWAP &&
!!formData[Key.value1] &&
!!Number(formData[Key.value1]) &&
!!from &&
!!to &&
isAutoRouterLoading
Expand Down
1 change: 1 addition & 0 deletions src/forms/SwapResultContents.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react"
import { SwapAttribute } from "types/swapTx"
import useSwapResults from "../hooks/useSwapResults"
import ConfirmDetails from "./ConfirmDetails"

Expand Down
2 changes: 1 addition & 1 deletion src/forms/SwapToken.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ $name: 14px;
.verified {
width: 40px;
height: auto;
font-family: OpenSans;
font-family: "Open Sans", arial, sans-serif;
font-size: 10px;
font-weight: 600;
font-stretch: normal;
Expand Down
Loading