|
| 1 | +import { WhirlpoolPositionInfo } from '@tools/sdk/orca/configuration'; |
| 2 | +import Select from './inputs/Select'; |
| 3 | + |
| 4 | +const SelectOrcaWhirlpoolPosition = ({ |
| 5 | + title, |
| 6 | + positionsInfo, |
| 7 | + selectedValue, |
| 8 | + onSelect, |
| 9 | +}: { |
| 10 | + title: string; |
| 11 | + positionsInfo: WhirlpoolPositionInfo[]; |
| 12 | + selectedValue?: WhirlpoolPositionInfo; |
| 13 | + onSelect: (positionInfo: WhirlpoolPositionInfo | null) => void; |
| 14 | +}) => { |
| 15 | + const getPositionDisplay = (positionInfo: WhirlpoolPositionInfo) => ( |
| 16 | + <div className="flex flex-col flex-wrap space-y-2"> |
| 17 | + <div className="flex w-full justify-between items-center flex-wrap"> |
| 18 | + <strong> |
| 19 | + Price range {positionInfo.tokenAName} per {positionInfo.tokenBName} |
| 20 | + </strong> |
| 21 | + <span> |
| 22 | + {positionInfo.uiLowerPrice} - {positionInfo.uiUpperPrice} |
| 23 | + </span> |
| 24 | + </div> |
| 25 | + |
| 26 | + <div className="flex w-full justify-between items-center flex-wrap"> |
| 27 | + <strong>Pubkey</strong> |
| 28 | + <span className="overflow-auto text-xs"> |
| 29 | + {positionInfo.publicKey.toBase58()} |
| 30 | + </span> |
| 31 | + </div> |
| 32 | + |
| 33 | + <div className="flex w-full justify-between items-center flex-wrap"> |
| 34 | + <strong>Liquidity</strong> |
| 35 | + <span>{positionInfo.liquidity}</span> |
| 36 | + </div> |
| 37 | + |
| 38 | + <div className="flex w-full justify-between items-center flex-wrap"> |
| 39 | + <strong>Position Mint</strong> |
| 40 | + <span className="overflow-auto text-xs"> |
| 41 | + {positionInfo.positionMint.toBase58()} |
| 42 | + </span> |
| 43 | + </div> |
| 44 | + </div> |
| 45 | + ); |
| 46 | + |
| 47 | + return ( |
| 48 | + <div className="flex flex-col"> |
| 49 | + <div className="mb-0.5">{title}</div> |
| 50 | + |
| 51 | + {positionsInfo.length ? ( |
| 52 | + <Select |
| 53 | + className="flex flex-col w-full" |
| 54 | + value={ |
| 55 | + selectedValue ? ( |
| 56 | + <> |
| 57 | + Position with price range {selectedValue.uiLowerPrice}/ |
| 58 | + {selectedValue.uiUpperPrice} ({selectedValue.tokenAName} per |
| 59 | + {selectedValue.tokenBName}) |
| 60 | + </> |
| 61 | + ) : null |
| 62 | + } |
| 63 | + onChange={(positionPublicKey: string) => |
| 64 | + onSelect( |
| 65 | + positionsInfo.find( |
| 66 | + (positionInfo) => |
| 67 | + positionInfo.publicKey.toBase58() === positionPublicKey, |
| 68 | + ) ?? null, |
| 69 | + ) |
| 70 | + } |
| 71 | + > |
| 72 | + {positionsInfo.map((positionInfo) => ( |
| 73 | + <Select.Option |
| 74 | + key={positionInfo.publicKey.toBase58()} |
| 75 | + value={positionInfo.publicKey.toBase58()} |
| 76 | + className="space-y-0.5 text-xs text-fgd-3" |
| 77 | + > |
| 78 | + {getPositionDisplay(positionInfo)} |
| 79 | + </Select.Option> |
| 80 | + ))} |
| 81 | + </Select> |
| 82 | + ) : ( |
| 83 | + <div>No position available</div> |
| 84 | + )} |
| 85 | + </div> |
| 86 | + ); |
| 87 | +}; |
| 88 | + |
| 89 | +export default SelectOrcaWhirlpoolPosition; |
0 commit comments