Skip to content

Commit

Permalink
Merge pull request #501 from invariant-labs/usd-tier
Browse files Browse the repository at this point in the history
Change tiers on USDC/USDT pair + Nightly Connect update
  • Loading branch information
wojciech-cichocki authored Oct 28, 2023
2 parents 14561fc + 9350c89 commit 4feba2e
Show file tree
Hide file tree
Showing 11 changed files with 324 additions and 31,218 deletions.
31,020 changes: 1 addition & 31,019 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DepositSelector from './DepositSelector'
import { SwapToken } from '@selectors/solanaWallet'
import { BN } from '@project-serum/anchor'
import { PublicKey } from '@solana/web3.js'
import { useState } from '@storybook/addons'

const tokens: SwapToken[] = [
{
Expand Down Expand Up @@ -35,37 +36,43 @@ const tokens: SwapToken[] = [
}
]

storiesOf('position/depositSelector', module).add('deposit', () => (
<DepositSelector
tokens={tokens}
setPositionTokens={() => {}}
onAddLiquidity={() => {}}
tokenAInputState={{
value: '0.000001',
setValue: () => {},
blocked: false,
decimalsLimit: 6
}}
tokenBInputState={{
value: '',
setValue: () => {},
blocked: true,
blockerInfo: 'Select a token.',
decimalsLimit: 8
}}
feeTiers={[0.02, 0.04, 0.1, 0.3, 1]}
progress='none'
onReverseTokens={() => {}}
poolIndex={0}
canCreateNewPool
canCreateNewPosition
handleAddToken={() => {}}
commonTokens={[
new PublicKey('So11111111111111111111111111111111111111112'),
new PublicKey('9n4nbM75f5Ui33ZbPYXn59EwSgE8CGsHtAeTH5YFeJ9E'),
new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v')
]}
initialHideUnknownTokensValue={false}
onHideUnknownTokensChange={() => {}}
/>
))
storiesOf('position/depositSelector', module).add('deposit', () => {
const [feeTierIndex, setFeeTierIndex] = useState<number>(0)
return (
<DepositSelector
tokens={tokens}
setPositionTokens={(_a, _b, fee) => {
setFeeTierIndex(fee)
}}
onAddLiquidity={() => {}}
tokenAInputState={{
value: '0.000001',
setValue: () => {},
blocked: false,
decimalsLimit: 6
}}
tokenBInputState={{
value: '',
setValue: () => {},
blocked: true,
blockerInfo: 'Select a token.',
decimalsLimit: 8
}}
feeTiers={[0.02, 0.04, 0.1, 0.3, 1]}
progress='none'
onReverseTokens={() => {}}
poolIndex={0}
canCreateNewPool
canCreateNewPosition
handleAddToken={() => {}}
commonTokens={[
new PublicKey('So11111111111111111111111111111111111111112'),
new PublicKey('9n4nbM75f5Ui33ZbPYXn59EwSgE8CGsHtAeTH5YFeJ9E'),
new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v')
]}
initialHideUnknownTokensValue={false}
onHideUnknownTokensChange={() => {}}
feeTierIndex={feeTierIndex}
/>
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface IDepositSelector {
onHideUnknownTokensChange: (val: boolean) => void
priceALoading?: boolean
priceBLoading?: boolean
feeTierIndex: number
}

export const DepositSelector: React.FC<IDepositSelector> = ({
Expand All @@ -78,13 +79,13 @@ export const DepositSelector: React.FC<IDepositSelector> = ({
initialHideUnknownTokensValue,
onHideUnknownTokensChange,
priceALoading,
priceBLoading
priceBLoading,
feeTierIndex
}) => {
const classes = useStyles()

const [tokenAIndex, setTokenAIndex] = useState<number | null>(null)
const [tokenBIndex, setTokenBIndex] = useState<number | null>(null)
const [feeTierIndex, setFeeTierIndex] = useState<number>(0)

const getButtonMessage = useCallback(() => {
if (tokenAIndex === null || tokenBIndex === null) {
Expand Down Expand Up @@ -212,12 +213,12 @@ export const DepositSelector: React.FC<IDepositSelector> = ({

<FeeSwitch
onSelect={fee => {
setFeeTierIndex(fee)
setPositionTokens(tokenAIndex, tokenBIndex, fee)
}}
feeTiers={feeTiers}
showOnlyPercents
bestTierIndex={bestTierIndex}
currentValue={feeTierIndex}
/>
</Grid>

Expand Down
7 changes: 7 additions & 0 deletions src/components/NewPosition/FeeSwitch/FeeSwitch.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react'
import { storiesOf } from '@storybook/react'
import FeeSwitch from './FeeSwitch'
import { useState } from '@storybook/addons'

storiesOf('position/feeSwitch', module)
.add('default', () => {
const [feeTierIndex, setFeeTierIndex] = useState<number>(0)
return (
<div
style={{
Expand All @@ -13,14 +15,17 @@ storiesOf('position/feeSwitch', module)
}}>
<FeeSwitch
onSelect={val => {
setFeeTierIndex(val)
console.log(val)
}}
feeTiers={[0.05, 0.3, 1]}
currentValue={feeTierIndex}
/>
</div>
)
})
.add('onlyPercents', () => {
const [feeTierIndex, setFeeTierIndex] = useState<number>(0)
return (
<div
style={{
Expand All @@ -30,10 +35,12 @@ storiesOf('position/feeSwitch', module)
}}>
<FeeSwitch
onSelect={val => {
setFeeTierIndex(val)
console.log(val)
}}
feeTiers={[0.02, 0.04, 0.1, 0.3, 1]}
showOnlyPercents
currentValue={feeTierIndex}
/>
</div>
)
Expand Down
8 changes: 4 additions & 4 deletions src/components/NewPosition/FeeSwitch/FeeSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ export interface IFeeSwitch {
showOnlyPercents?: boolean
feeTiers: number[]
bestTierIndex?: number
currentValue: number
}

export const FeeSwitch: React.FC<IFeeSwitch> = ({
onSelect,
showOnlyPercents = false,
feeTiers,
bestTierIndex
bestTierIndex,
currentValue
}) => {
const classes = useStyles()

const [current, setCurrent] = useState(0)
const [blocked, setBlocked] = useState(false)

const tabsClasses = useTabsStyles()
const singleTabClasses = useSingleTabStyles()

const handleChange = (_: React.ChangeEvent<{}>, newValue: number) => {
if (!blocked) {
setCurrent(newValue)
onSelect(newValue)
setBlocked(true)
setTimeout(() => {
Expand All @@ -38,7 +38,7 @@ export const FeeSwitch: React.FC<IFeeSwitch> = ({
return (
<Grid className={classes.wrapper}>
<Tabs
value={current}
value={currentValue}
onChange={handleChange}
variant='scrollable'
scrollButtons='auto'
Expand Down
Loading

0 comments on commit 4feba2e

Please sign in to comment.