Skip to content

Commit

Permalink
Merge pull request #789 from invariant-labs/staging
Browse files Browse the repository at this point in the history
Update prod env
  • Loading branch information
wojciech-cichocki authored Nov 21, 2024
2 parents 0f1fc60 + d5f952a commit 1ad7713
Show file tree
Hide file tree
Showing 14 changed files with 3,668 additions and 2,876 deletions.
1 change: 0 additions & 1 deletion src/components/Header/HeaderButton/ChangeWalletButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const ChangeWalletButton: React.FC<IProps> = ({
const [isChangeWallet, setIsChangeWallet] = React.useState<boolean>(false)

const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
console.log('connected', connected)
if (!connected) {
setIsOpenSelectWallet(true)
setAnchorEl(event.currentTarget)
Expand Down
69 changes: 35 additions & 34 deletions src/containers/HeaderWrapper/HeaderWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import React, { useEffect, useMemo } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useLocation, useNavigate } from 'react-router-dom'
import { actions as snackbarsActions } from '@store/reducers/snackbars'
import { changeToNightlyAdapter, connectStaticWallet } from '@utils/web3/wallet'
import { changeToNightlyAdapter, connectStaticWallet, getSolanaWallet } from '@utils/web3/wallet'
import { sleep } from '@invariant-labs/sdk'

export const HeaderWrapper: React.FC = () => {
const dispatch = useDispatch()
Expand All @@ -25,44 +26,46 @@ export const HeaderWrapper: React.FC = () => {
useEffect(() => {
const reconnectStaticWallet = async (wallet: WalletType) => {
await connectStaticWallet(wallet)
dispatch(walletActions.connect())
dispatch(walletActions.connect(true))
}

if (currentNetwork === NetworkType.Testnet) {
dispatch(actions.setNetwork(NetworkType.Devnet))
dispatch(actions.setRPCAddress(RPC.DEV))
}

const walletType = localStorage.getItem('WALLET_TYPE') as WalletType | null

if (walletType !== null && walletType === WalletType.NIGHTLY) {
nightlyConnectAdapter.addListener('connect', () => {
const eagerConnectToNightly = async () => {
try {
changeToNightlyAdapter()
dispatch(walletActions.connect())
})
const nightlyAdapter = getSolanaWallet()

if (nightlyConnectAdapter.connected) {
changeToNightlyAdapter()
dispatch(walletActions.connect())
await nightlyAdapter.connect()
await sleep(500)
if (!nightlyAdapter.connected) {
await nightlyAdapter.connect()
await sleep(500)
}
dispatch(walletActions.connect(true))
} catch (error) {
console.error('Error during Nightly eager connection:', error)
}
}

;(async () => {
if (currentNetwork === NetworkType.Testnet) {
dispatch(actions.setNetwork(NetworkType.Devnet))
dispatch(actions.setRPCAddress(RPC.DEV))
}

nightlyConnectAdapter.canEagerConnect().then(
async canEagerConnect => {
if (canEagerConnect) {
changeToNightlyAdapter()
await nightlyConnectAdapter.connect()
}
},
error => {
console.log(error)
const walletType = localStorage.getItem('WALLET_TYPE') as WalletType | null

if (walletType === WalletType.NIGHTLY) {
const canEagerConnect = await nightlyConnectAdapter.canEagerConnect().catch(error => {
console.error('Error checking eager connect:', error)
return false
})
if (canEagerConnect) {
await eagerConnectToNightly()
}
)
} else {
if (!walletType || walletType === null) {
return
} else if (walletType) {
await reconnectStaticWallet(walletType)
}
reconnectStaticWallet(walletType)
}
})()
}, [])

const defaultTestnetRPC = useMemo(() => {
Expand Down Expand Up @@ -150,8 +153,6 @@ export const HeaderWrapper: React.FC = () => {
<Header
address={walletAddress}
onNetworkSelect={(network, rpcAddress) => {
console.log('network', network)
console.log('rpcAddress', rpcAddress)
if (rpcAddress !== currentRpc) {
localStorage.setItem(`INVARIANT_RPC_SOLANA_${network}`, rpcAddress)
dispatch(actions.setRPCAddress(rpcAddress))
Expand All @@ -173,7 +174,7 @@ export const HeaderWrapper: React.FC = () => {
}
}}
onConnectWallet={() => {
dispatch(walletActions.connect())
dispatch(walletActions.connect(false))
}}
landing={location.pathname.substring(1)}
walletConnected={walletStatus === Status.Initialized}
Expand Down
21 changes: 12 additions & 9 deletions src/containers/NewPositionWrapper/NewPositionWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
calcPriceBySqrtPrice,
calcPriceByTickIndex,
createPlaceholderLiquidityPlot,
getJupTokenPrice,
getTokenPrice,
getJupTokensRatioPrice,
getNewTokenOrThrow,
printBN,
Expand Down Expand Up @@ -413,11 +413,14 @@ export const NewPositionWrapper: React.FC<IProps> = ({
if (tokenA === null || (tokenA !== null && !tokens[tokenA.toString()])) {
return
}

console.log(tokens[tokenA.toString()])
if (tokenA) {
setPriceALoading(true)
getJupTokenPrice(tokenA.toString())
.then(data => setTokenAPriceData(data))
getTokenPrice(tokenA.toString(), tokens[tokenA.toString()]?.coingeckoId)
.then(data => {
console.log('data', data)
return setTokenAPriceData(data)
})
.catch(() => setTokenAPriceData(undefined))
.finally(() => setPriceALoading(false))
} else {
Expand Down Expand Up @@ -448,7 +451,7 @@ export const NewPositionWrapper: React.FC<IProps> = ({
}

setPriceBLoading(true)
getJupTokenPrice(tokenB.toString())
getTokenPrice(tokenB.toString(), tokens[tokenB.toString()].coingeckoId)
.then(data => setTokenBPriceData(data))
.catch(() => setTokenBPriceData(undefined))
.finally(() => setPriceBLoading(false))
Expand Down Expand Up @@ -582,7 +585,7 @@ export const NewPositionWrapper: React.FC<IProps> = ({

if (tokenA) {
setPriceALoading(true)
await getJupTokenPrice(tokenA.toString())
await getTokenPrice(tokenA.toString(), tokens[tokenA.toString()].coingeckoId)
.then(data => setTokenAPriceData(data))
.catch(() => setTokenAPriceData(undefined))
.finally(() => setPriceALoading(false))
Expand All @@ -592,7 +595,7 @@ export const NewPositionWrapper: React.FC<IProps> = ({

if (tokenB) {
setPriceBLoading(true)
getJupTokenPrice(tokenB.toString())
getTokenPrice(tokenB.toString(), tokens[tokenB.toString()].coingeckoId)
.then(data => setTokenBPriceData(data))
.catch(() => setTokenBPriceData(undefined))
.finally(() => setPriceBLoading(false))
Expand Down Expand Up @@ -779,7 +782,7 @@ export const NewPositionWrapper: React.FC<IProps> = ({
solBalance={solBalance}
walletStatus={walletStatus}
onConnectWallet={() => {
dispatch(walletActions.connect())
dispatch(walletActions.connect(false))
}}
onDisconnectWallet={() => {
dispatch(walletActions.disconnect())
Expand All @@ -789,7 +792,7 @@ export const NewPositionWrapper: React.FC<IProps> = ({
loadingTicksAndTickMaps={loadingTicksAndTickMaps}
noConnectedBlockerProps={{
onConnect: () => {
dispatch(walletActions.connect())
dispatch(walletActions.connect(false))
},
descCustomText: 'Cannot add any liquidity.'
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
calcPriceByTickIndex,
calcYPerXPriceBySqrtPrice,
createPlaceholderLiquidityPlot,
getJupTokenPrice,
getTokenPrice,
getJupTokensRatioPrice,
initialXtoY,
printBN
Expand Down Expand Up @@ -337,7 +337,7 @@ export const SinglePositionWrapper: React.FC<IProps> = ({ id }) => {

const xId = position.tokenX.assetAddress.toString() ?? ''
if (xId.length) {
getJupTokenPrice(xId)
getTokenPrice(xId, position.tokenX.coingeckoId)
.then(data => setTokenXPriceData(data))
.catch(() => setTokenXPriceData(undefined))
} else {
Expand All @@ -346,7 +346,7 @@ export const SinglePositionWrapper: React.FC<IProps> = ({ id }) => {

const yId = position.tokenY.assetAddress.toString() ?? ''
if (yId.length) {
getJupTokenPrice(yId)
getTokenPrice(yId, position.tokenY.coingeckoId)
.then(data => setTokenYPriceData(data))
.catch(() => setTokenYPriceData(undefined))
} else {
Expand Down Expand Up @@ -552,7 +552,7 @@ export const SinglePositionWrapper: React.FC<IProps> = ({ id }) => {
className={classes.fullHeightContainer}>
<NoConnected
onConnect={() => {
dispatch(walletActions.connect())
dispatch(walletActions.connect(false))
}}
title='Connect a wallet to view your position,'
descCustomText='or start exploring liquidity pools now!'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const WrappedPositionsList: React.FC = () => {
itemsPerPage={POSITIONS_PER_PAGE}
noConnectedBlockerProps={{
onConnect: () => {
dispatch(walletActions.connect())
dispatch(walletActions.connect(false))
},
title: 'Start exploring liquidity pools right now!',
descCustomText: 'Or, connect your wallet to see existing positions, and create a new one!'
Expand Down
12 changes: 6 additions & 6 deletions src/containers/WrappedSwap/WrappedSwap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import {
addNewTokenToLocalStorage,
getJupTokenPrice,
getTokenPrice,
getNewTokenOrThrow,
tickerToAddress
} from '@utils/utils'
Expand Down Expand Up @@ -188,7 +188,7 @@ export const WrappedSwap = ({ initialTokenFrom, initialTokenTo }: Props) => {
const id = tokensDict[tokenFrom.toString()]?.assetAddress.toString() ?? ''
if (id) {
setPriceFromLoading(true)
getJupTokenPrice(id)
getTokenPrice(id, tokensDict[tokenFrom.toString()].coingeckoId)
.then(data => setTokenFromPriceData(data))
.catch(() => setTokenFromPriceData(undefined))
.finally(() => setPriceFromLoading(false))
Expand All @@ -208,7 +208,7 @@ export const WrappedSwap = ({ initialTokenFrom, initialTokenTo }: Props) => {
const id = tokensDict[tokenTo.toString()]?.assetAddress.toString() ?? ''
if (id) {
setPriceToLoading(true)
getJupTokenPrice(id)
getTokenPrice(id, tokensDict[tokenTo.toString()].coingeckoId)
.then(data => setTokenToPriceData(data))
.catch(() => setTokenToPriceData(undefined))
.finally(() => setPriceToLoading(false))
Expand Down Expand Up @@ -240,7 +240,7 @@ export const WrappedSwap = ({ initialTokenFrom, initialTokenTo }: Props) => {
const idFrom = tokensDict[tokenFrom.toString()].assetAddress.toString() ?? ''
if (idFrom) {
setPriceFromLoading(true)
getJupTokenPrice(idFrom)
getTokenPrice(idFrom, tokensDict[tokenFrom.toString()].coingeckoId)
.then(data => setTokenFromPriceData(data))
.catch(() => setTokenFromPriceData(undefined))
.finally(() => setPriceFromLoading(false))
Expand All @@ -251,7 +251,7 @@ export const WrappedSwap = ({ initialTokenFrom, initialTokenTo }: Props) => {
const idTo = tokensDict[tokenTo.toString()].assetAddress.toString() ?? ''
if (idTo) {
setPriceToLoading(true)
getJupTokenPrice(idTo)
getTokenPrice(idTo, tokensDict[tokenTo.toString()].coingeckoId)
.then(data => setTokenToPriceData(data))
.catch(() => setTokenToPriceData(undefined))
.finally(() => setPriceToLoading(false))
Expand Down Expand Up @@ -337,7 +337,7 @@ export const WrappedSwap = ({ initialTokenFrom, initialTokenTo }: Props) => {
}
}}
onConnectWallet={() => {
dispatch(walletActions.connect())
dispatch(walletActions.connect(false))
}}
onDisconnectWallet={() => {
dispatch(walletActions.disconnect())
Expand Down
34 changes: 32 additions & 2 deletions src/store/consts/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,33 @@ export const DOGIN_MAIN: Token = {
'https://statics.solscan.io/cdn/imgs/s60?ref=68747470733a2f2f697066732e696f2f697066732f516d5066614a565454534c537a6f566161754d4b416e36586132627337365965564d44455269617934556d583562'
}

export const SNY_MAIN: Token = {
symbol: 'SNY',
address: new PublicKey('4dmKkXNHdgYsXqBHCuMikNQWwVomZURhYvkkX5c4pQ7y'),
decimals: 6,
name: 'Synthetify',
logoURI:
'https://statics.solscan.io/cdn/imgs/s60?ref=68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f736f6c616e612d6c6162732f746f6b656e2d6c6973742f6d61696e2f6173736574732f6d61696e6e65742f34646d4b6b584e48646759735871424843754d696b4e515777566f6d5a55526859766b6b58356334705137792f6c6f676f2e706e67',
coingeckoId: 'synthetify-token'
}

export const WEN_MAIN: Token = {
symbol: 'WEN',
address: new PublicKey('WENWENvqqNya429ubCdR81ZmD69brwQaaBYY6p3LCpk'),
decimals: 5,
name: 'Wen',
logoURI: 'https://assets.coingecko.com/coins/images/34856/standard/wen-solana.png?1707872119'
}

export const SUI_MAIN: Token = {
symbol: 'SUI',
address: new PublicKey('G1vJEgzepqhnVu35BN4jrkv3wVwkujYWFFCxhbEZ1CZr'),
decimals: 8,
name: 'Sui (Wormhole)',
logoURI:
'https://assets.coingecko.com/coins/images/26375/standard/sui-ocean-square.png?1727791290'
}

export enum RPC {
DEV = 'https://api.devnet.solana.com',
TEST = 'https://api.testnet.solana.com',
Expand Down Expand Up @@ -397,9 +424,12 @@ export const getAddressTickerMap = (network: NetworkType): { [k: string]: string
mSOL: 'mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So',
bSOL: 'bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1',
stSOL: '7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj',
SNY: '4dmKkXNHdgYsXqBHCuMikNQWwVomZURhYvkkX5c4pQ7y',
ETH: '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs',
LFNTY: 'LFNTYraetVioAPnGJht4yNg2aUZFXR776cMeN9VMjXp'
LFNTY: 'LFNTYraetVioAPnGJht4yNg2aUZFXR776cMeN9VMjXp',
DOGIN: DOGIN_MAIN.address.toString(),
SNY: SNY_MAIN.address.toString(),
WEN: WEN_MAIN.address.toString(),
SUI: SUI_MAIN.address.toString()
}
} else {
return {}
Expand Down
Loading

0 comments on commit 1ad7713

Please sign in to comment.