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

Pancake zap in widget #2556

Open
wants to merge 80 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
8b41b9f
widget test
viet-nv Apr 1, 2024
51c1ae7
feat: pancake test
viet-nv Jun 7, 2024
25683c7
fix: modal
viet-nv Jun 7, 2024
05ccb75
chore: update version
viet-nv Jun 10, 2024
c13f156
pump widget ver
viet-nv Jun 10, 2024
f038a40
pump widget version
viet-nv Jun 10, 2024
5726c07
pump widget version
viet-nv Jun 12, 2024
1f6efd0
pump widget version
viet-nv Jun 12, 2024
11ba38a
pump widget version
viet-nv Jun 13, 2024
60342fb
pump widget version
viet-nv Jun 13, 2024
e239dd9
pump widget version
viet-nv Jun 13, 2024
2f9d56d
pump
viet-nv Jun 14, 2024
eba9686
pump
viet-nv Jun 14, 2024
d015a9b
pump version
viet-nv Jun 14, 2024
233eb06
pump version
viet-nv Jun 14, 2024
e9b6266
pump version
viet-nv Jun 14, 2024
d2f9097
pump version
viet-nv Jun 14, 2024
041415a
pump version
viet-nv Jun 14, 2024
e9efb2f
pump version
viet-nv Jun 14, 2024
35e5f39
pump version
viet-nv Jun 14, 2024
5913691
pump version
viet-nv Jun 14, 2024
a553573
widget prod test
viet-nv Jun 14, 2024
04ac57a
feat: add gas fee
viet-nv Jun 14, 2024
b6ec24a
fix: gas fee tooltip
viet-nv Jun 14, 2024
d0de6a1
fix: gas fee tooltip
viet-nv Jun 14, 2024
b22fe94
fix: pool estimated price after zap
viet-nv Jun 16, 2024
e3ac7a1
pump widget version
viet-nv Jun 18, 2024
91eadcd
feat: improvement warning and display info
viet-nv Jun 19, 2024
4ac8dec
tmp
viet-nv Jun 24, 2024
9f22bb0
remove styled
viet-nv Jun 26, 2024
2a9c5bf
fix: pos id
viet-nv Jul 12, 2024
085a5b6
fix: pos id
viet-nv Jul 12, 2024
8a25616
multiple token
viet-nv Aug 13, 2024
fffdd68
fix: liq widget version
viet-nv Aug 14, 2024
d2fdbdc
feat: import token
viet-nv Aug 22, 2024
e905bd6
Fix zap in multi token widget
tienkane Oct 1, 2024
001b177
Fix text color
tienkane Oct 1, 2024
b5ee92d
Add Zap summary
tienkane Oct 1, 2024
d802e4a
Add fee & fix protocol name
tienkane Oct 1, 2024
255a41d
Change zap in widget lib to new repo version
tienkane Oct 2, 2024
d785f22
Update new zap in widget version
tienkane Oct 3, 2024
dacd803
Update zap in widget version
tienkane Oct 3, 2024
d0d27d7
Update new zap in widget version
tienkane Oct 3, 2024
8790c4f
add new zap in widget version & add a default pool address
tienkane Oct 3, 2024
66a5b8f
Add new zap in widget version
tienkane Oct 3, 2024
030cdb3
add zap in widget new version
tienkane Oct 4, 2024
4f6d3e5
Add new zap in widget version
tienkane Oct 4, 2024
a9d0167
Hide liquidity chart
tienkane Oct 4, 2024
0a10c3f
Fix some UI
tienkane Oct 4, 2024
9a7559c
Add import token & change logic get zap route api even when insuffici…
tienkane Oct 7, 2024
3414ee8
Fix warning logic
tienkane Oct 8, 2024
836f287
Fix increase liquidity UI
tienkane Oct 8, 2024
2c59a01
Add security to token info
tienkane Oct 9, 2024
59e5225
Update
tienkane Oct 10, 2024
0bf95db
.
tienkane Oct 10, 2024
1789a01
Update
tienkane Oct 10, 2024
e48505d
Update
tienkane Oct 10, 2024
40909a1
Update
tienkane Oct 14, 2024
de4ad6e
Update
tienkane Oct 14, 2024
1e569b1
Update
tienkane Oct 14, 2024
db571cd
Update
tienkane Oct 14, 2024
e90f169
Update
tienkane Oct 14, 2024
67460c6
Update
tienkane Oct 15, 2024
bc38ff1
Update
tienkane Oct 15, 2024
c9c3fe6
set up demo version for pancake widget
tienkane Nov 5, 2024
061d6e6
pull main
tienkane Nov 5, 2024
de9dc36
update
tienkane Nov 5, 2024
8037646
add connect wallet fn
tienkane Nov 5, 2024
a289f9c
update
tienkane Nov 5, 2024
6c3198c
Update handling token select modal
tienkane Nov 5, 2024
d7abbe0
update
tienkane Nov 5, 2024
92d3cd2
update
tienkane Nov 6, 2024
3a2e562
fix token selected handling
tienkane Nov 6, 2024
bf6f8a1
add default token pair if empty
tienkane Nov 6, 2024
3b42bfe
update
tienkane Nov 6, 2024
669d7f9
update
tienkane Nov 6, 2024
942938c
update
tienkane Nov 6, 2024
e743116
update
tienkane Nov 6, 2024
9c61763
update
tienkane Nov 6, 2024
9ce7515
update version
tienkane Nov 15, 2024
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
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
href="https://fonts.googleapis.com/css2?family=Work+Sans:wght@300;400;500;600&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Kanit:400,500,600,700" />

<title>KyberSwap - Limitless Access To DeFi</title>
<script>
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@
"@blocto/wagmi-connector": "^2.0.4",
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@holdstation/paymaster-helper": "^2.0.20",
"@kyberswap/krystal-walletconnect-v2": "0.0.1",
"@kyberswap/ks-sdk-classic": "^1.0.3",
"@kyberswap/ks-sdk-core": "1.1.6",
"@kyberswap/ks-sdk-elastic": "^1.1.2",
"@kyberswap/pancake-liquidity-widgets": "1.0.1",
"@kyberswap/oauth2": "1.0.2",
"@lingui/macro": "^4.6.0",
"@lingui/react": "^4.6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/groups/SwapNavGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const SwapNavGroup = () => {
</IconWrapper>
<Flex alignItems={'center'} sx={{ flex: 1 }} justifyContent={'space-between'}>
<Trans>Cross-Chain</Trans>
<img src={SquidLogoLight} alt="kyberswap with Squid" height={16} />
<img src={SquidLogoLight} alt="kyberswap with Squid" style={{ height: 16 }} />
</Flex>
</Flex>
</StyledNavLink>
Expand Down
3 changes: 3 additions & 0 deletions src/pages/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { RedirectPathToSwapV3Network } from 'pages/SwapV3/redirects'
import { useHolidayMode } from 'state/user/hooks'
import { isSupportLimitOrder } from 'utils'

import LiquidityWidget from './LiquidityWidget'
import VerifyAuth from './Verify/VerifyAuth'

const Login = lazy(() => import('./Oauth/Login'))
Expand Down Expand Up @@ -308,6 +309,8 @@ export default function App() {

<Route path={APP_PATHS.ELASTIC_SNAPSHOT} element={<ElasticSnapshot />} />
<Route path={APP_PATHS.MARKET_OVERVIEW} element={<MarketOverview />} />
<Route path={APP_PATHS.ELASTIC_SNAPSHOT} element={<ElasticSnapshot />} />
<Route path="/liquidity-widget" element={<LiquidityWidget />} />

<Route path={APP_PATHS.AGGREGATOR_CAMPAIGN} element={<Campaign />} />
<Route path={APP_PATHS.LIMIT_ORDER_CAMPAIGN} element={<Campaign />} />
Expand Down
215 changes: 215 additions & 0 deletions src/pages/LiquidityWidget.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
import { ChainId } from '@kyberswap/ks-sdk-core'
import { LiquidityWidget as KsLiquidityWidget } from '@kyberswap/pancake-liquidity-widgets'
import '@kyberswap/pancake-liquidity-widgets/dist/style.css'
import { useCallback, useEffect, useState } from 'react'
import { Box } from 'rebass'
import { useAccount, useWalletClient } from 'wagmi'

import { ButtonPrimary } from 'components/Button'
import Input from 'components/Input'
import { NetworkSelector } from 'components/NetworkSelector'
import CurrencySearchModal from 'components/SearchModal/CurrencySearchModal'
import { ETHER_ADDRESS } from 'constants/index'
import { useActiveWeb3React } from 'hooks'
import { useChangeNetwork } from 'hooks/web3/useChangeNetwork'
import { useWalletModalToggle } from 'state/application/hooks'

enum Theme {
DARK = 'dark',
LIGHT = 'light',
}

export default function LiquidityWidget() {
const [selectedChainId, setSelectedChainId] = useState(ChainId.ARBITRUM)
const [theme, setTheme] = useState<Theme>(Theme.DARK)
const [poolAddress, setPoolAddress] = useState('0x389938cf14be379217570d8e4619e51fbdafaa21')
const [positionId, setPositionId] = useState('')
const [feeAddress, setFeeAddress] = useState('')
const [feePcm, setFeePcm] = useState(0)
const [openModal, setOpenModal] = useState(false)
const [autoAfterChange, setAutoAfterChange] = useState(false)

const [initDepositTokens, setInitDepositTokens] = useState<string>(
'0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9,0x912CE59144191C1204E64559FE8253a0e49E6548',
)
const [initAmounts, setInitAmounts] = useState<string>(',')
const [openTokenSelectModal, setOpenTokenSelectModal] = useState(false)

const { chainId } = useActiveWeb3React()
const { data: walletClient } = useWalletClient()
const { address: account } = useAccount()
const toggleWalletModal = useWalletModalToggle()
const { changeNetwork } = useChangeNetwork()

useEffect(() => {
if (autoAfterChange && chainId === selectedChainId) {
setOpenModal(true)
setAutoAfterChange(false)
}
}, [autoAfterChange, chainId, selectedChainId])

const handleDismiss = () => setOpenTokenSelectModal(false)

const handleSelectToken = (token: any) => {
const selectedToken =
token.wrapped && !token.isNative ? { ...token, ...token.wrapped } : { ...token, address: ETHER_ADDRESS }
const tokens = initDepositTokens.split(',')
const indexOfToken = tokens.findIndex(t => t.toLowerCase() === selectedToken.address?.toLowerCase())

if (indexOfToken > -1) return
setInitDepositTokens(
initDepositTokens ? `${initDepositTokens},${selectedToken.address}` : `${selectedToken.address}`,
)
setInitAmounts(initAmounts ? `${initAmounts},` : '')

handleDismiss()
}

// required
const handleAddTokens = useCallback(
(tokenAddresses: string) => {
setInitDepositTokens(initDepositTokens ? `${initDepositTokens},${tokenAddresses}` : tokenAddresses)
const amountsToAdd = tokenAddresses
.split('')
.filter(item => item === ',')
.join('')
setInitAmounts(initAmounts ? `${initAmounts},${amountsToAdd}` : amountsToAdd)
},
[initAmounts, initDepositTokens],
)

// required
const handleRemoveToken = useCallback(
(tokenAddress: string) => {
const tokens = initDepositTokens.split(',')
const indexOfToken = tokens.findIndex(t => t.toLowerCase() === tokenAddress.toLowerCase())
if (indexOfToken === -1) return

tokens.splice(indexOfToken, 1)
const amounts = initAmounts.split(',')
amounts.splice(indexOfToken, 1)
setInitDepositTokens(tokens.join(','))
setInitAmounts(amounts.join(','))
},
[initAmounts, initDepositTokens],
)

// required
const handleAmountChange = useCallback(
(tokenAddress: string, amount: string) => {
const tokens = initDepositTokens.split(',')
const indexOfToken = tokens.findIndex(t => t.toLowerCase() === tokenAddress.toLowerCase())
if (indexOfToken === -1) return

const amounts = initAmounts.split(',')
amounts[indexOfToken] = amount
setInitAmounts(amounts.join(','))
},
[initAmounts, initDepositTokens],
)

// required
const handleOpenTokenSelectModal = useCallback(() => setOpenTokenSelectModal(true), [])

return (
<>
{openModal ? (
<>
<KsLiquidityWidget
theme={theme}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
walletClient={walletClient as any}
account={account}
chainId={selectedChainId}
networkChainId={chainId}
initTickLower={undefined}
initTickUpper={undefined}
poolAddress={poolAddress}
positionId={positionId}
feeAddress="0xB82bb6Ce9A249076Ca7135470e7CA634806De168"
feePcm={0}
source="zap-widget-demo"
includedSources={undefined}
excludedSources={undefined}
initDepositTokens={initDepositTokens}
initAmounts={initAmounts}
onConnectWallet={toggleWalletModal}
onDismiss={() => window.location.reload()}
onTxSubmit={undefined}
onAddTokens={handleAddTokens}
onRemoveToken={handleRemoveToken}
onAmountChange={handleAmountChange}
onOpenTokenSelectModal={handleOpenTokenSelectModal}
/>
<CurrencySearchModal
isOpen={openTokenSelectModal}
onDismiss={handleDismiss}
onCurrencySelect={handleSelectToken}
/>
</>
) : (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
maxWidth: '500px',
gap: '1rem',
width: '100%',
color: '#fff',
}}
>
<NetworkSelector chainId={selectedChainId} customOnSelectNetwork={chain => setSelectedChainId(chain)} />

<div style={{ display: 'flex', justifyContent: 'space-around' }}>
<div>
<input
type="radio"
id="darktheme"
value={Theme.DARK}
checked={theme === Theme.DARK}
onChange={e => setTheme(e.currentTarget.value as Theme)}
/>
  <label htmlFor="darktheme">Dark Theme</label>
</div>
<div>
<input
type="radio"
id="lighttheme"
value={Theme.LIGHT}
checked={theme === Theme.LIGHT}
onChange={e => setTheme(e.currentTarget.value as Theme)}
/>
  <label htmlFor="lighttheme">Light Theme</label>
</div>
</div>

<Input placeholder="Pool address..." value={poolAddress} onChange={e => setPoolAddress(e.target.value)} />
<Input placeholder="Position id..." value={positionId} onChange={e => setPositionId(e.target.value)} />

<Input
placeholder="initDepositTokens..."
value={initDepositTokens}
onChange={e => setInitDepositTokens(e.target.value)}
/>
<Input placeholder="initAmounts..." value={initAmounts} onChange={e => setInitAmounts(e.target.value)} />

<Input placeholder="Fee address..." value={feeAddress} onChange={e => setFeeAddress(e.target.value)} />
<Input placeholder="Fee pcm..." value={feePcm} onChange={e => setFeePcm(+e.target.value)} />

<ButtonPrimary
onClick={() => {
if (selectedChainId !== chainId) {
changeNetwork(selectedChainId)
setAutoAfterChange(true)
} else {
setOpenModal(true)
}
}}
>
Load
</ButtonPrimary>
</Box>
)}
</>
)
}
9 changes: 9 additions & 0 deletions src/theme/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,13 @@ export const ThemedGlobalStyle = createGlobalStyle`
padding-right: 1.5rem;
}

.ks-lw-modal-overlay {
z-index: 9999
}

.ks-lw {
width: 100%;
/* max-width: 900px; */
}

`
24 changes: 19 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"compilerOptions": {
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": false,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
Expand All @@ -22,13 +26,23 @@
"jsx": "react-jsx",
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"typeRoots": ["./types"],
"typeRoots": [
"./types"
],
"baseUrl": "src",
"useUnknownInCatchVariables": false,
"paths": {
"@/*": ["./src/*"]
"@/*": [
"./src/*"
]
}
},
"exclude": ["node_modules", "cypress"],
"include": ["./src/**/*.ts", "./src/**/*.tsx"]
"exclude": [
"node_modules",
"cypress"
],
"include": [
"./src/**/*.ts",
"./src/**/*.tsx"
]
}
Loading
Loading