-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/paltalabs/defindex into fea…
…t/githubWorkflow
- Loading branch information
Showing
21 changed files
with
346 additions
and
16,412 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,15 @@ | ||
"use client"; | ||
import { Container } from '@chakra-ui/react' | ||
import { useSorobanReact } from '@soroban-react/core' | ||
import { DeployIndex } from "../src/components/DeployIndex/DeployIndex"; | ||
import ConnectButton from "@/components/Wallet/ConnectButton"; | ||
import ManageIndexes from '@/components/ManageIndexes/ManageIndexes'; | ||
|
||
export default function Home() { | ||
const { address } = useSorobanReact() | ||
return ( | ||
<Container textAlign={'center'} mt={16} mx={0} px={0} minW={'100vw'}> | ||
<ConnectButton /> | ||
{address && ( | ||
<Container centerContent minW={'100vw'}> | ||
<ManageIndexes /> | ||
{/* <DeployIndex /> */} | ||
</Container> | ||
)} | ||
<Container mt={16} mx={0} px={0} minW={'100vw'}> | ||
<Container centerContent textAlign={'center'} minW={'100vw'}> | ||
<ManageIndexes /> | ||
</Container> | ||
</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
147 changes: 0 additions & 147 deletions
147
apps/dapp/src/components/DeployIndex/AddNewAdapterButton.tsx
This file was deleted.
Oops, something went wrong.
121 changes: 121 additions & 0 deletions
121
apps/dapp/src/components/DeployIndex/AddNewStrategyButton.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,121 @@ | ||
import { useEffect, useState } from 'react' | ||
import { | ||
Button, | ||
Modal, | ||
ModalOverlay, | ||
ModalContent, | ||
ModalHeader, | ||
ModalFooter, | ||
ModalBody, | ||
ModalCloseButton, | ||
useDisclosure, | ||
IconButton, | ||
FormControl, | ||
Select, | ||
Input | ||
} from '@chakra-ui/react' | ||
import { AddIcon } from '@chakra-ui/icons' | ||
import { useAppDispatch, useAppSelector } from '@/store/lib/storeHooks' | ||
import { pushStrategy, getDefaultStrategies, Strategy } from '@/store/lib/features/strategiesStore' | ||
import { useSorobanReact } from '@soroban-react/core' | ||
|
||
interface DefaultStrategy { | ||
name: string; | ||
address: string; | ||
value: number; | ||
} | ||
|
||
|
||
function AddNewStrategyButton() { | ||
const strategies = useAppSelector(state => state.strategies.strategies) | ||
const dispatch = useAppDispatch(); | ||
const { activeChain } = useSorobanReact() | ||
const [defaultStrategies, setDefaultStrategies] = useState<Strategy[]>([]) | ||
const [newStrategy, setNewStrategy] = useState<Strategy>() | ||
const [newAddress, setNewAddress] = useState<string>() | ||
const [newName, setNewName] = useState<string>() | ||
const [selectValue, setSelectValue] = useState<string>('') | ||
|
||
|
||
useEffect(() => { | ||
const fetchStragegies = async () => { | ||
const tempStrategies = await getDefaultStrategies(activeChain?.name?.toLowerCase() || 'testnet') | ||
setDefaultStrategies(tempStrategies) | ||
} | ||
fetchStragegies() | ||
}, [activeChain?.networkPassphrase]) | ||
|
||
const { isOpen, onOpen, onClose } = useDisclosure() | ||
const handleOpenModal = () => { | ||
isOpen ? onClose() : onOpen() | ||
} | ||
|
||
const resetForm = () => { | ||
setNewStrategy({ address: '', name: '', value: 0 }) | ||
setNewAddress('') | ||
setNewName('') | ||
setSelectValue('') | ||
} | ||
|
||
const handleInputSelect = async (e: any) => { | ||
const value = e.target.value | ||
setSelectValue(value) | ||
const isDefaultStrategy = await defaultStrategies.find(strategy => strategy.address === value) | ||
if (!!isDefaultStrategy) { | ||
setNewStrategy(isDefaultStrategy) | ||
} | ||
} | ||
|
||
const addStrategy = async () => { | ||
const isDefaultStrategy = await defaultStrategies.find(strategy => strategy.address === newStrategy?.address) | ||
const hasEmptyFields = newStrategy?.address === '' || newStrategy?.name === '' || newName === '' || newAddress === '' | ||
const strategyExists = strategies.find((strategy: Strategy) => strategy.address === newStrategy?.address) | ||
if (strategyExists) { | ||
console.error('Strategy already exists') | ||
return false | ||
} | ||
if (hasEmptyFields && !isDefaultStrategy) { | ||
console.error('Please fill all fields') | ||
return false | ||
} | ||
await dispatch(pushStrategy(newStrategy!)) | ||
resetForm() | ||
isOpen ? onClose() : onOpen() | ||
} | ||
return ( | ||
<> | ||
<Button colorScheme="green" size="md" onClick={handleOpenModal} textAlign={'end'} isDisabled={defaultStrategies.length === 0}> | ||
Add new strategy | ||
</Button> | ||
<Modal isOpen={isOpen} onClose={onClose} isCentered> | ||
<ModalOverlay backdropFilter='blur(5px)' /> | ||
<ModalContent > | ||
<ModalHeader>Add new strategy</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
|
||
<Select placeholder='Select option' onChange={handleInputSelect} value={selectValue}> | ||
{defaultStrategies.map((strategy, index) => ( | ||
<option key={strategy.name} value={strategy.address}>{(strategy.name != '') ? strategy.name : strategy.address}</option> | ||
))} | ||
</Select> | ||
</ModalBody> | ||
|
||
<ModalFooter> | ||
<Button variant='ghost' mr={3} onClick={onClose}> | ||
Close | ||
</Button> | ||
<IconButton | ||
aria-label='add_strategy' | ||
colorScheme='green' | ||
icon={<AddIcon />} | ||
onClick={addStrategy} | ||
/> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
) | ||
} | ||
|
||
export default AddNewStrategyButton |
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
Oops, something went wrong.