Skip to content
Open

Gj #2

Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .cssrem
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rootFontSize": 16,
"fixedDigits": 3
}
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@craco/craco": "^6.4.3",
"@rbl/terminal-library": "git+https://github.com/Rome-Blockchain-Labs/terminal-library.git#8dda04858acb1c45437325857eff56c60afca5ee",
"@rbl/velox-common": "4.1.3",
"@reduxjs/toolkit": "^1.8.0",
Expand All @@ -16,14 +17,16 @@
"graphql-request": "^4.2.0",
"lodash": "^4.17.21",
"react": "^17.0.2",
"react-accessible-accordion": "^4.0.0",
"react-dom": "^17.0.2",
"react-redux": "^7.2.6",
"react-router": "^6.2.2",
"react-router-dom": "^6.2.2",
"react-scripts": "5.0.0",
"react-virtualized": "^9.22.3",
"reactstrap": "^9.0.1",
"styled-components": "^5.3.3",
"styled-components": "^5.3.5",
"twin.macro": "^2.8.2",
"typescript": "^4.6.2",
"web-vitals": "^2.1.4"
},
Expand Down Expand Up @@ -51,5 +54,17 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/core": "^7.17.8",
"autoprefixer": "^10.4.4",
"babel-plugin-macros": "^3.1.0",
"postcss": "^8.4.12",
"tailwindcss": "^3.0.23"
},
"babelMacros": {
"twin": {
"preset": "styled-components"
}
}
}
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function App() {
<Provider store={store}>
<br/><br/><br/><br/><br/><br/>
<br/><br/>
<div style={{width:"500px", margin:"auto", border:"solid"}}>
<div style={{width:"500px", margin:"auto"}}>
<TokenSearch />
{/* <iframe loading={"lazy"} src={"http://localhost:3000/cookieFramed.html"} height={500}/>*/}
</div>
Expand Down
16 changes: 16 additions & 0 deletions src/Components/Chip/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { memo } from 'react';
import './style.css'

export const Chip = memo(
(props) => {
const {label, checked, onChange, name, value} = props
return (
<>
<input type="checkbox" id={`${label}-${name}`} onChange={onChange} checked={checked} name={name} value={value}/>
<label htmlFor={`${label}-${name}`}>{label} </label>
</>
)
}
)

export default Chip
27 changes: 27 additions & 0 deletions src/Components/Chip/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
input[type="checkbox"] {
display: none;
}

input[type="checkbox"] + label {
-webkit-transition: all 500ms ease;
transition: all 500ms ease;
font-size: 14px;
cursor: pointer;
border-radius: 5px;
background-color: #fff;
border:solid 2px #7d7d7d;
padding: 0.1rem 0.3rem;
display: inline-block;
-moz-user-select: -moz-none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
margin: 5px;
}


input[type="checkbox"]:checked + label {
-webkit-transition: all 500ms ease;
transition: all 500ms ease;
background-color: #666699; color: white; border-color:#666699;
}
31 changes: 31 additions & 0 deletions src/Components/accordion.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

.accordion__button {
background-color: #f4f4f4;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
text-align: left;
border: none;
}

.accordion__button:hover {
background-color: #ddd;
}

.accordion__button:after {
display: block;
content: '';
float: right;
height: 10px;
width: 10px;
margin-right: 12px;
border-bottom: 2px solid currentColor;
border-right: 2px solid currentColor;
transform: rotate(-45deg);
}

.accordion__button[aria-expanded='true']::after,
.accordion__button[aria-selected='true']::after {
transform: rotate(45deg);
}
4 changes: 4 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
Expand Down
63 changes: 56 additions & 7 deletions src/redux/tokenSearchSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
import retry from 'async-retry';
import { stringify } from 'flatted';
import { searchTokensAsync } from "../tokenSearch/helpers/async";
import { uniq, omitBy } from "lodash"
import { uniq, omitBy, uniqBy } from "lodash"
import { networkExchangePairs } from '../tokenSearch/helpers/config';

export const setPair = createAsyncThunk(
Expand Down Expand Up @@ -118,6 +118,20 @@ export const searchTokenPairs = createAsyncThunk(
}
}
);
const initNetworks = uniq(networkExchangePairs
.map(pair => pair[0]))
.map(networkName => networkName).reduce((k, v) => ({...k, [v]: false}), {})

const initExchanges = {}
uniq(networkExchangePairs.map((exchange) => {
const netName = exchange[0]
const exchangeName = exchange[1]

if (!Object.keys(initExchanges).includes(netName))
initExchanges[netName] = {}
initExchanges[netName][exchangeName] = false
return false
}))

const initialTimestamp = new Date().getTime();
const initialState = {
Expand All @@ -129,8 +143,8 @@ const initialState = {
selectedPair: undefined,
serializedTradeEstimator: '',
suggestions: [],
exchangeMap: {},
networkMap: {}
exchangeMap: initExchanges,
networkMap: initNetworks
};

export const tokenSearchSlice = createSlice({
Expand Down Expand Up @@ -188,12 +202,47 @@ export const tokenSearchSlice = createSlice({
state.isSelecting = !state.isSelecting;
},
setExchangeMap: (state, action) => {
state.exchangeMap[action.payload.exchangeName] = action.payload.checked
const {checked, exchangeName, networkName} = action.payload


if (exchangeName === 'all') {
uniq(networkExchangePairs).map(pair => {
const exName = pair[1]
const netName = pair[0]

if (!Object.keys(state.exchangeMap).includes(netName))
state.exchangeMap[netName] = {}

state.exchangeMap[netName][exName] = checked
return checked
})
} else {
if (networkName !== undefined)
state.exchangeMap[networkName][exchangeName] = checked

Object.keys(state.networkMap).filter(netName => {
if(state.networkMap[netName] === true && Object.keys(state.exchangeMap[netName]).includes(exchangeName.toString())) {
state.exchangeMap[netName][exchangeName] = checked
}
return false
})

}
},

setNetworkMap: (state, action) => {
console.log(action)
state.networkMap[action.payload.networkName] = action.payload.checked
}
const {checked, networkName} = action.payload

if (networkName === 'all') {
const allNetworks = uniq(networkExchangePairs
.map(pair => pair[0]))
.map(networkName => networkName)
allNetworks.forEach((network) => {
state.networkMap[network] = checked
})
} else
state.networkMap[networkName] = checked
},
},
});

Expand Down
43 changes: 43 additions & 0 deletions src/tokenSearch/NetworkFilter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from "react"
import { useDispatch, useSelector } from 'react-redux';

import {
Accordion,
AccordionItem,
AccordionItemHeading,
AccordionItemButton,
AccordionItemPanel,
} from 'react-accessible-accordion';
//import 'react-accessible-accordion/dist/fancy-example.css';
import SearchNetworks from "./SearchNetworks";
import SearchExchanges from "./SearchExchanges";

import './../Components/accordion.css'

export const NetworkFilter = () => {
const { isSelecting, searchText, exchangeMap, networkMap } = useSelector(
(state) => state
);

return (<>
<Accordion allowZeroExpanded>
<AccordionItem>
<AccordionItemHeading>
<AccordionItemButton >
Filter Networks: search {}
</AccordionItemButton>
</AccordionItemHeading>
<AccordionItemPanel>
{<SearchNetworks />}
{<SearchExchanges />}
</AccordionItemPanel>
</AccordionItem>

</Accordion>
</>


)
}

export default NetworkFilter
58 changes: 34 additions & 24 deletions src/tokenSearch/SearchExchanges.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react"
import React, { useMemo, useState, useEffect } from "react"
import { uniqBy } from "lodash"
import { networkExchangePairs } from "./helpers/config";
import { useDispatch, useSelector } from 'react-redux';
import { setExchangeMap } from "../redux/tokenSearchSlice";
import styled from 'styled-components';

import Chip from '../Components/Chip';

const ExchangeList = styled.div`
border-top:solid 1px #000;
Expand All @@ -13,34 +13,44 @@ const ExchangeList = styled.div`
justify-content:center;
padding:3px;
`;


//todo new file
const ExchangeSelection = ({ exchangeName }) => {
const dispatch = useDispatch();
const { exchangeMap } = useSelector((state) => state);

return <>
<input
checked={exchangeMap[exchangeName] || false}
type="checkbox"
onChange={(e) => dispatch(setExchangeMap({ exchangeName, checked: e.target.checked }))}
/>
{exchangeName}
</>
}


export const SearchExchanges = () => {
const { networkMap } = useSelector((state) => state);


const dispatch = useDispatch();
const { exchangeMap, networkMap } = useSelector((state) => state);
console.log('networkMap]: ', networkMap)
console.log('exchangeMap]: ', exchangeMap)
const handleChange = (e) => {
const {checked, value } = e.target
const data = value.split('-')
const networkName = data[0]
const exchangeName = data[1]
dispatch(setExchangeMap({ exchangeName, checked, networkName }));
}

const selectedNets = Object.keys(networkMap).filter((key) => networkMap[key] === true)
const exchanges = Object.fromEntries(Object.entries(exchangeMap).filter(([key, value]) => {
return selectedNets.includes(key.toString()) && exchangeMap[key]
}))

const isAllChecked = useMemo(() => {
const checked = Object.keys(exchanges).every(network => {
const result = Object.values(exchanges[network]).every((value) => {
return value
})
return result
})
return checked
}, [exchanges])

return (
<>
<ExchangeList>
{<ExchangeSelection key={'*'} exchangeName={'All'} />}
<Chip label='All' onChange={handleChange} key={'allExchanges'} name='exchanges' value='-all' checked={isAllChecked} />

{uniqBy(networkExchangePairs.filter(pair => networkMap[pair[0]]), 1).map(pair => {
const exchangeName = pair[1]
return <ExchangeSelection key={exchangeName} exchangeName={exchangeName} />
const networkName = pair[0]
return <Chip key={exchangeName} label={exchangeName} onChange={handleChange} name='exchanges' value={`${networkName}-${exchangeName}`} checked={exchangeMap[networkName][exchangeName]}/>
})}
</ExchangeList>
</>
Expand Down
Loading