-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
352 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ListItemButton as MuiListItemButton } from '@mui/material'; | ||
import { styled } from '@mui/material/styles'; | ||
import { getContrastAlphaColor } from '../utils'; | ||
|
||
export const ListItemButton = styled(MuiListItemButton)(({ theme }) => ({ | ||
borderRadius: theme.shape.borderRadius, | ||
paddingLeft: theme.spacing(1.5), | ||
height: 56, | ||
'&:hover': { | ||
backgroundColor: getContrastAlphaColor(theme, '4%'), | ||
}, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ListItemText as MuiListItemText } from '@mui/material'; | ||
import { listItemTextClasses } from '@mui/material/ListItemText'; | ||
import { styled } from '@mui/material/styles'; | ||
|
||
export const ListItemText = styled(MuiListItemText)(({ theme }) => ({ | ||
[`.${listItemTextClasses.primary}`]: { | ||
fontWeight: 400, | ||
}, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 3 additions & 10 deletions
13
packages/widget/src/components/TokenList/TokenList.style.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const env = { | ||
LIFI_API_URL: 'https://li.quest/v1/', // 'https://developkub.li.finance/v1/', | ||
LIFI_API_URL: 'https://li.quest/v1/', // 'https://develop.li.quest/v1/', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,42 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
import type { Bridge, Exchange } from '@lifi/sdk'; | ||
import type { ToolsResponse } from '@lifi/sdk'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useMemo } from 'react'; | ||
import { isItemAllowed, useLiFi, useWidgetConfig } from '../providers'; | ||
import { useSettingsStoreContext } from '../stores'; | ||
|
||
interface WidgetBridge extends Omit<Bridge, 'key'> { | ||
key: string; | ||
} | ||
|
||
type FormattedTool<T, K extends keyof T> = Record<string, Pick<T, K>>; | ||
|
||
export const useTools = () => { | ||
const lifi = useLiFi(); | ||
const { bridges, exchanges } = useWidgetConfig(); | ||
const settingsStoreContext = useSettingsStoreContext(); | ||
const { data } = useQuery(['tools'], () => lifi.getTools(), { | ||
onSuccess(data) { | ||
const { initializeTools } = settingsStoreContext.getState(); | ||
initializeTools( | ||
'Bridges', | ||
data.bridges | ||
.filter((bridge) => isItemAllowed(bridge.key, bridges)) | ||
.map((bridge) => bridge.key), | ||
); | ||
initializeTools( | ||
'Exchanges', | ||
data.exchanges | ||
.filter((exchange) => isItemAllowed(exchange.key, exchanges)) | ||
.map((exchange) => exchange.key), | ||
); | ||
const { data } = useQuery( | ||
['tools'], | ||
async (): Promise<ToolsResponse> => { | ||
const tools = await lifi.getTools(); | ||
return { | ||
bridges: tools.bridges.filter((bridge) => | ||
isItemAllowed(bridge.key, bridges), | ||
), | ||
exchanges: tools.exchanges.filter((exchange) => | ||
isItemAllowed(exchange.key, exchanges), | ||
), | ||
}; | ||
}, | ||
{ | ||
onSuccess(data) { | ||
const { initializeTools } = settingsStoreContext.getState(); | ||
initializeTools( | ||
'Bridges', | ||
data.bridges.map((bridge) => bridge.key), | ||
); | ||
initializeTools( | ||
'Exchanges', | ||
data.exchanges.map((exchange) => exchange.key), | ||
); | ||
}, | ||
refetchInterval: 180000, | ||
staleTime: 180000, | ||
}, | ||
refetchInterval: 180000, | ||
staleTime: 180000, | ||
}); | ||
|
||
const formattedTools = useMemo( | ||
() => ({ | ||
bridges: data?.bridges.reduce((bridges, bridge) => { | ||
bridges[bridge.key] = bridge; | ||
return bridges; | ||
}, {} as FormattedTool<WidgetBridge, 'key' | 'name' | 'logoURI'>), | ||
exchanges: data?.exchanges.reduce((exchanges, exchange) => { | ||
exchanges[exchange.key] = exchange; | ||
return exchanges; | ||
}, {} as FormattedTool<Exchange, 'key' | 'name' | 'logoURI'>), | ||
}), | ||
[data?.bridges, data?.exchanges], | ||
); | ||
|
||
return { tools: data, formattedTools }; | ||
return { tools: data }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
packages/widget/src/pages/SelectChainPage/SelectChainPage.style.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
packages/widget/src/pages/SelectEnabledToolsPage/SelectEnabledToolsPage.style.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { styled } from '@mui/material/styles'; | ||
import { ListItemButton as ListItemButtonBase } from '../../components/ListItemButton'; | ||
|
||
export const ListItemButton = styled(ListItemButtonBase)(({ theme }) => ({ | ||
paddingRight: theme.spacing(1), | ||
})); |
105 changes: 105 additions & 0 deletions
105
packages/widget/src/pages/SelectEnabledToolsPage/SelectEnabledToolsPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { | ||
CheckBox, | ||
CheckBoxOutlineBlankOutlined, | ||
CheckBoxOutlined, | ||
IndeterminateCheckBoxOutlined, | ||
} from '@mui/icons-material'; | ||
import { | ||
Avatar, | ||
Container, | ||
IconButton, | ||
List, | ||
ListItemAvatar, | ||
} from '@mui/material'; | ||
import { useHeaderActionStore } from '../../components/Header'; | ||
|
||
import { useEffect } from 'react'; | ||
import { shallow } from 'zustand/shallow'; | ||
import { ListItemText } from '../../components/ListItemText'; | ||
import { useTools } from '../../hooks'; | ||
import { useSettingsStore } from '../../stores'; | ||
import { ListItemButton } from './SelectEnabledToolsPage.style'; | ||
|
||
export const SelectEnabledToolsPage: React.FC<{ | ||
type: 'Bridges' | 'Exchanges'; | ||
}> = ({ type }) => { | ||
const typeKey = type.toLowerCase() as 'bridges' | 'exchanges'; | ||
const { tools } = useTools(); | ||
const [enabledTools, setTools] = useSettingsStore( | ||
(state) => [state[`enabled${type}`], state.setTools], | ||
shallow, | ||
); | ||
|
||
const handleClick = (key: string) => { | ||
if (!tools) { | ||
return; | ||
} | ||
const toolKeys = tools[typeKey].map((tool) => tool.key); | ||
if (enabledTools?.includes(key)) { | ||
setTools( | ||
type, | ||
enabledTools.filter((toolKey) => toolKey !== key), | ||
toolKeys, | ||
); | ||
} else { | ||
setTools(type, [...enabledTools, key], toolKeys); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
const allToolsSelected = tools?.[typeKey].length === enabledTools.length; | ||
const toggleCheckboxes = () => { | ||
if (!tools) { | ||
return; | ||
} | ||
const toolKeys = tools[typeKey].map((tool) => tool.key); | ||
if (allToolsSelected) { | ||
setTools(type, [], toolKeys); | ||
} else { | ||
setTools(type, toolKeys, toolKeys); | ||
} | ||
}; | ||
return useHeaderActionStore.getState().setAction( | ||
<IconButton size="medium" edge="end" onClick={toggleCheckboxes}> | ||
{allToolsSelected ? ( | ||
<CheckBoxOutlined /> | ||
) : enabledTools.length ? ( | ||
<IndeterminateCheckBoxOutlined /> | ||
) : ( | ||
<CheckBoxOutlineBlankOutlined /> | ||
)} | ||
</IconButton>, | ||
); | ||
}, [enabledTools.length, setTools, tools, type, typeKey]); | ||
|
||
return ( | ||
<Container disableGutters> | ||
<List | ||
sx={{ | ||
paddingLeft: 1.5, | ||
paddingRight: 1.5, | ||
}} | ||
> | ||
{tools?.[typeKey].map((tool) => ( | ||
<ListItemButton | ||
key={tool.name} | ||
onClick={() => handleClick(tool.key)} | ||
disableRipple | ||
> | ||
<ListItemAvatar> | ||
<Avatar src={tool.logoURI} alt={tool.name}> | ||
{tool.name[0]} | ||
</Avatar> | ||
</ListItemAvatar> | ||
<ListItemText primary={tool.name} /> | ||
{enabledTools?.includes(tool.key) ? ( | ||
<CheckBox color="primary" /> | ||
) : ( | ||
<CheckBoxOutlineBlankOutlined /> | ||
)} | ||
</ListItemButton> | ||
))} | ||
</List> | ||
</Container> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './SelectEnabledToolsPage'; |
Oops, something went wrong.