Skip to content

Commit 0ebd656

Browse files
Merge pull request #279 from invariant-labs/dev
Update staging
2 parents 37315e6 + b469de2 commit 0ebd656

File tree

6 files changed

+53
-26
lines changed

6 files changed

+53
-26
lines changed

package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Swap/Swap.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,16 @@ export const Swap: React.FC<ISwap> = ({
211211

212212
useEffect(() => {
213213
if (tokenFrom !== null && tokenTo !== null) {
214-
if (inputRef === inputTarget.FROM) {
214+
if (inputRef === inputTarget.FROM && tokens[tokenTo]) {
215215
const amount = getAmountOut(tokens[tokenTo])
216216
setAmountTo(+amount === 0 ? '' : trimLeadingZeros(amount))
217-
} else {
217+
} else if (tokens[tokenFrom]) {
218218
const amount = getAmountOut(tokens[tokenFrom])
219219
setAmountFrom(+amount === 0 ? '' : trimLeadingZeros(amount))
220+
} else if (!tokens[tokenTo]) {
221+
setAmountTo('')
222+
} else if (!tokens[tokenFrom]) {
223+
setAmountFrom('')
220224
}
221225
}
222226
}, [simulateResult])
@@ -474,11 +478,15 @@ export const Swap: React.FC<ISwap> = ({
474478
<ExchangeAmountInput
475479
value={amountFrom}
476480
balance={
477-
tokenFrom !== null
481+
tokenFrom !== null && tokens[tokenFrom]
478482
? printBigint(tokens[tokenFrom].balance || 0n, tokens[tokenFrom].decimals)
479483
: '- -'
480484
}
481-
decimal={tokenFrom !== null ? tokens[tokenFrom].decimals : DEFAULT_TOKEN_DECIMAL}
485+
decimal={
486+
tokenFrom !== null && tokens[tokenFrom]
487+
? tokens[tokenFrom].decimals
488+
: DEFAULT_TOKEN_DECIMAL
489+
}
482490
className={classes.amountInput}
483491
setValue={value => {
484492
if (value.match(/^\d*\.?\d*$/)) {
@@ -557,12 +565,14 @@ export const Swap: React.FC<ISwap> = ({
557565
<ExchangeAmountInput
558566
value={amountTo}
559567
balance={
560-
tokenTo !== null
561-
? printBigint(tokens[tokenTo].balance || 0n, tokens[tokenTo].decimals)
568+
tokenTo !== null && tokens[tokenTo]
569+
? printBigint(tokens[tokenTo]?.balance || 0n, tokens[tokenTo]?.decimals)
562570
: '- -'
563571
}
564572
className={classes.amountInput}
565-
decimal={tokenTo !== null ? tokens[tokenTo].decimals : DEFAULT_TOKEN_DECIMAL}
573+
decimal={
574+
tokenTo !== null && tokens[tokenTo] ? tokens[tokenTo].decimals : DEFAULT_TOKEN_DECIMAL
575+
}
566576
setValue={value => {
567577
if (value.match(/^\d*\.?\d*$/)) {
568578
setAmountTo(value)

src/containers/WrappedSwap/WrappedSwap.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ export const WrappedSwap = ({ initialTokenFrom, initialTokenTo }: Props) => {
8686
}, [isFetchingNewPool])
8787

8888
const lastTokenFrom =
89-
tickerToAddress(initialTokenFrom) ||
90-
localStorage.getItem(`INVARIANT_LAST_TOKEN_FROM_${network}`)
89+
tickerToAddress(initialTokenFrom) && initialTokenFrom !== '-'
90+
? tickerToAddress(initialTokenFrom)
91+
: localStorage.getItem(`INVARIANT_LAST_TOKEN_FROM_${network}`)
92+
9193
const lastTokenTo =
92-
tickerToAddress(initialTokenTo) || localStorage.getItem(`INVARIANT_LAST_TOKEN_TO_${network}`)
94+
tickerToAddress(initialTokenTo) && initialTokenTo !== '-'
95+
? tickerToAddress(initialTokenTo)
96+
: localStorage.getItem(`INVARIANT_LAST_TOKEN_TO_${network}`)
9397

9498
const addTokenHandler = async (address: string) => {
9599
const psp22 = SingletonPSP22.getInstance()
@@ -145,7 +149,7 @@ export const WrappedSwap = ({ initialTokenFrom, initialTokenTo }: Props) => {
145149
return
146150
}
147151

148-
const id = tokensDict[tokenFrom.toString()].coingeckoId ?? ''
152+
const id = tokensDict[tokenFrom.toString()]?.coingeckoId || ''
149153

150154
if (id.length) {
151155
setPriceFromLoading(true)
@@ -169,7 +173,7 @@ export const WrappedSwap = ({ initialTokenFrom, initialTokenTo }: Props) => {
169173
return
170174
}
171175

172-
const id = tokensDict[tokenTo.toString()].coingeckoId ?? ''
176+
const id = tokensDict[tokenTo.toString()]?.coingeckoId || ''
173177
if (id.length) {
174178
setPriceToLoading(true)
175179
getCoinGeckoTokenPrice(id)
@@ -291,7 +295,13 @@ export const WrappedSwap = ({ initialTokenFrom, initialTokenTo }: Props) => {
291295
if (tokenTo !== null) {
292296
localStorage.setItem(`INVARIANT_LAST_TOKEN_TO_${network}`, tokenTo.toString())
293297
}
294-
if (tokenFrom !== null && tokenTo !== null && tokenFrom !== tokenTo) {
298+
if (
299+
tokenFrom !== null &&
300+
tokenTo !== null &&
301+
tokenFrom !== tokenTo &&
302+
tokenFrom !== '-' &&
303+
tokenTo !== '-'
304+
) {
295305
dispatch(
296306
poolsActions.getAllPoolsForPairData({
297307
first: tokenFrom,

src/store/sagas/pools.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,20 @@ export function* fetchAllPoolKeys(): Generator {
103103
}
104104

105105
export function* fetchAllPoolsForPairData(action: PayloadAction<PairTokens>) {
106-
const invariant = yield* getInvariant()
106+
try {
107+
const invariant = yield* getInvariant()
107108

108-
const token0 = action.payload.first.toString()
109-
const token1 = action.payload.second.toString()
110-
const poolPairs = yield* call([invariant, invariant.getAllPoolsForPair], token0, token1)
111-
const poolsWithPoolKey: PoolWithPoolKey[] = poolPairs.map(([feeTier, pool]) => {
112-
return { poolKey: newPoolKey(token0, token1, feeTier), ...pool }
113-
})
109+
const token0 = action.payload.first.toString()
110+
const token1 = action.payload.second.toString()
111+
const poolPairs = yield* call([invariant, invariant.getAllPoolsForPair], token0, token1)
112+
const poolsWithPoolKey: PoolWithPoolKey[] = poolPairs.map(([feeTier, pool]) => {
113+
return { poolKey: newPoolKey(token0, token1, feeTier), ...pool }
114+
})
114115

115-
yield* put(actions.addPools(poolsWithPoolKey))
116+
yield* put(actions.addPools(poolsWithPoolKey))
117+
} catch (error) {
118+
console.log(error)
119+
}
116120
}
117121

118122
export function* fetchTicksAndTickMaps(action: PayloadAction<FetchTicksAndTickMaps>) {

src/store/sagas/wallet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,11 @@ export function* handleGetBalances(action: PayloadAction<string[]>): Generator {
285285
}
286286

287287
export function* connectHandler(): Generator {
288-
yield takeLatest(actions.connect, handleConnect)
288+
yield takeLeading(actions.connect, handleConnect)
289289
}
290290

291291
export function* disconnectHandler(): Generator {
292-
yield takeLatest(actions.disconnect, handleDisconnect)
292+
yield takeLeading(actions.disconnect, handleDisconnect)
293293
}
294294

295295
export function* airdropSaga(): Generator {

src/utils/web3/selector.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export interface ConnectionOptions {
99
let _adapter: NightlyConnectAdapter | undefined
1010
export const nightlyConnectAdapter = async (
1111
persisted = true,
12-
connectionOptions: ConnectionOptions = {}
12+
connectionOptions: ConnectionOptions = {
13+
initOnConnect: true
14+
}
1315
) => {
1416
if (_adapter) return _adapter
1517
_adapter = await NightlyConnectAdapter.build(

0 commit comments

Comments
 (0)