Skip to content

Commit

Permalink
Feat/synapse UI max (#932)
Browse files Browse the repository at this point in the history
* Update TokenInput onClickMax button to work, wrap in useCallback

* Fix Max input for TokenInput

* Update input to hide scrollbar

* Fix Deposit bug

* Wrap sumBigNUmbersFromState with useCallback to update when args change

* Scratch above

* Fix Pools approve function to point towards correct approver address

* Input autocomplete off

* Update PoolsCardTitle to not set via innerHtml

* Line up LoadingSpinner to start of div, account for before pseudoclass

* Update LoadingSpinner to not affect other instances

* ..

* Fix cypress gh actions issue

* ...

* Update DestinationTx.tsx

* i think

---------

Co-authored-by: Jonah Lin <[email protected]>
Co-authored-by: Simon <[email protected]>
  • Loading branch information
3 people authored May 18, 2023
1 parent d574fed commit 66f3dc4
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ const InteractiveInputRow = ({
>
<div className="overflow-x-scroll ">
<input
autoComplete="off"
className={`
${isConnected ? '-mt-2' : '-mt-0'}
focus:outline-none bg-transparent
w-[300px] max-w-[calc(100%-92px)]
sm:min-w-[200px] sm:w-full
sm:min-w-[200px] sm:w-full scrollbar-none
placeholder:text-[#88818C] text-white
text-opacity-80 text-lg md:text-2xl lg:text-2xl font-medium
`}
Expand Down
19 changes: 9 additions & 10 deletions packages/synapse-interface/components/TokenInput.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { useCallback, MouseEvent } from 'react'
import InteractiveInputRow from './InteractiveInputRow'
import { formatBNToString } from '@bignumber/format'
import { formatUnits } from '@ethersproject/units'
import { displaySymbol } from '@utils/displaySymbol'
import { Token } from '@types'
import { BigNumber } from 'ethers'
import { cleanNumberInput } from '@utils/cleanNumberInput'

const TokenInput = ({
Expand All @@ -23,13 +21,14 @@ const TokenInput = ({
}) => {
const symbol = displaySymbol(chainId, token)

const onClickMax = (e) => {
e.preventDefault()
const maxStr = formatUnits(balanceStr, token.decimals[chainId])
if (maxStr != 'undefined') {
onChange(maxStr)
}
}
const onClickMax = useCallback(
(e: MouseEvent<HTMLButtonElement>) => {
e.preventDefault()
onChange(balanceStr)
},
[onChange, balanceStr, token]
)

return (
<div className="items-center">
<div className="w-full">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const BridgeInputContainer = ({
}
value={inputString}
name="inputRow"
autoComplete="off"
/>
)}
{isOrigin && isConnected && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
export default function LoadingSpinner({ className }: { className?: string }) {
export default function LoadingSpinner({
className,
shift = false,
}: {
className?: string
shift?: boolean
}) {
return (
<div
className={`inline-flex items-center justify-center pr-3 ${className}`}
>
<div className="dot-flashing"></div>
<div className={`dot-flashing ${shift ? 'left-[12px]' : ''}`}></div>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
} from '@utils/bridgeWatcher'
const DestinationTx = memo((fromEvent: BridgeWatcherTx) => {
const [toEvent, setToEvent] = useState<BridgeWatcherTx>()
const [toSynapseContract, setToSynapseContract] = useState<Contract>()
const [toSynapseContract, setToSynapseContract] =
useState<Contract>(undefined)
const [toSigner, setToSigner] = useState<Signer>()
const { data: toSignerRaw } = useSigner({ chainId: fromEvent.toChainId })
const [completedConf, setCompletedConf] = useState(false)
Expand Down Expand Up @@ -89,7 +90,7 @@ const DestinationTx = memo((fromEvent: BridgeWatcherTx) => {
)
}
setAttempted(true)
return
return null
}

useEffect(() => {
Expand All @@ -109,7 +110,7 @@ const DestinationTx = memo((fromEvent: BridgeWatcherTx) => {
toEvent === undefined &&
attempted
) {
= getToBridgeEvent().then((tx) => {
getToBridgeEvent().then((tx) => {
setToEvent(tx)
})
}
Expand All @@ -118,8 +119,10 @@ const DestinationTx = memo((fromEvent: BridgeWatcherTx) => {
if (toSynapseContract && toEvent === undefined && !completedConf) {
getToBridgeEvent().then((tx) => {
setToEvent(tx)
return
})
}
return
}, [toSynapseContract])
useEffect(() => {
setToSigner(toSignerRaw)
Expand Down
10 changes: 6 additions & 4 deletions packages/synapse-interface/pages/pool/poolManagement/Deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ const Deposit = ({
let sum = Zero
pool?.poolTokens &&
pool.poolTokens.map((token) => {
if (inputValue.bn[getAddress(token.addresses[chainId])]) {
if (!token.addresses[chainId]) return
const tokenAddress = getAddress(token.addresses[chainId])
if (inputValue.bn[tokenAddress]) {
sum = sum.add(
inputValue.bn[getAddress(token.addresses[chainId])].mul(
BigNumber.from(10).pow(18 - token.decimals[chainId])
Expand All @@ -77,7 +79,7 @@ const Deposit = ({
let allowances: Record<string, BigNumber> = {}
for (const [key, value] of Object.entries(inputValue.bn)) {
allowances[key] = await getTokenAllowance(
pool.addresses[chainId],
pool.swapAddresses[chainId],
key,
address,
chainId
Expand Down Expand Up @@ -113,7 +115,7 @@ const Deposit = ({

useEffect(() => {
calculateMaxDeposits()
}, [inputValue, time])
}, [inputValue, time, pool, chainId, address])

const onChangeInputValue = (token: Token, value: string) => {
const bigNum = stringToBigNum(value, token.decimals[chainId]) ?? Zero
Expand Down Expand Up @@ -232,7 +234,7 @@ const Deposit = ({
)
}
const correctToken = (token: Token) => {
let balanceToken
let balanceToken: Token | undefined
if (token.symbol == WETH.symbol) {
balanceToken = ETH
} else if (token.symbol == AVWETH.symbol) {
Expand Down
12 changes: 5 additions & 7 deletions packages/synapse-interface/pages/pools/PoolCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ const PoolsListCard = memo(
chainName={chain?.name}
/>
}
titleClassName="text-white font-light text-xl lg:min-w-[333px]"
titleClassName="text-white font-light text-xl"
className={`
bg-bgBase transition-all rounded-xl items-center
hover:bg-bgLight
py-6 mt-4 pr-2
py-6 mt-4
border border-transparent
whitespace-wrap
`}
Expand All @@ -110,8 +110,7 @@ const PoolsListCard = memo(
{poolData?.totalLockedUSDStr ? (
'$' + poolData?.totalLockedUSDStr
) : (
// <div className="w-12 h-6 rounded animate-pulse bg-slate-700" />
<LoadingSpinner />
<LoadingSpinner shift={true} />
)}
</div>
</div>
Expand Down Expand Up @@ -145,13 +144,12 @@ const PoolsCardTitle = ({
poolName: string
chainImg: string
}) => {
let displayPoolName = poolName?.replace(chainName, `<b>${chainName}</b>`)
let displayPoolName = poolName?.replace(chainName, `${chainName}`)

return (
<div className="flex items-center">
<img src={chainImg} className="w-6 h-6 mr-2 rounded-full" />
{/* TODO: A better way to do this? */}
<div dangerouslySetInnerHTML={{ __html: displayPoolName }} />
<div className="font-semibold">{displayPoolName}</div>
</div>
)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/synapse-interface/pages/swap/SwapCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ const SwapCard = ({
wallet
)
const allowance = await erc20.allowance(address, routerAddress)
console.log('allowance from getCurrentTokenAllowance: ', allowance)
return allowance
}

Expand Down Expand Up @@ -531,6 +532,9 @@ const SwapCard = ({
z-20 rounded-3xl
`,
}

console.log('swapQuote?.allowance: ', swapQuote?.allowance)

// TODO make this a function
const ActionButton = useMemo(() => {
let destAddrNotValid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const approve = async (

if (token.symbol != WETH.symbol) {
await approveToken(
pool.addresses[chainId],
pool.swapAddresses[chainId],
chainId,
token.symbol === AVWETH.symbol
? WETHE.addresses[chainId]
Expand Down Expand Up @@ -58,8 +58,10 @@ export const deposit = async (

toast('Starting your deposit...')

const result = Array.from(Object.values(inputAmounts), (value) => value)

let spendTransactionArgs = [
Object.values(inputAmounts),
result,
minToMint,
Math.round(new Date().getTime() / 1000 + 60 * 10),
]
Expand All @@ -69,6 +71,7 @@ export const deposit = async (
)

const tx = await spendTransaction.wait()

const toastContent = (
<div>
<div>Liquidity added!</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export const useSwapDepositContract = async (pool: Token, chainId: number) => {

const swapContract = new Contract(poolAddress, abi, signer)

console.log('swapContract: ', swapContract)
return swapContract
}

0 comments on commit 66f3dc4

Please sign in to comment.