PlacePosition.tsx
Go to src/components/PlacePosition.tsx
where we will be building our next component to handle placing positions.
Importing Dependencies:
Import the required dependencies
Setting up our component
Create a functional component
PlacePosition
which will take in 3 propspariPubkey
,side
, andamount
In the component, use the
useConnection
anduseWallet
hooks to retrieve the connection and public key. Also, initialize aparimutuelWeb3
instance with the requiredconfig
andconnection
Get the
pariPubkey
,side
, andamount
props passed to the component
Use the
useEffect
hook to run a piece of code whenever thepariPubkey
value changes
Create a
onClick
event handler using theuseCallback
hook. This event handler will be called when the button is clicked, and it will make a call to theparimutuelWeb3.placePosition
method to place a position.
The required parameters are: - wallet
- PublicKey(pariPubkey)
- parseFloat(amount) * (10 ** 9 / 1)
- side
- Date.now()
Use
side
to determine the color gradient of the button. If the side is equal toPositionSideEnum.LONG
, the button will have a gradient from purple to teal. If the side is equal toPositionSideEnum.SHORT
, the button will have a gradient from pink to yellow.
Returning our component
Return the following to set up the PlacePosition button:
The PlacePosition button checks whether the user input an amount, and will block the user from placing a position if they have not
Now, let us test it!
Head over to
src/components/PlacePostionBox.tsx
Import PlacePosition from our component
Place two instances of
PlacePosition
under the<input/>
element, one for placing Long positions and the other one for Shorts, and pass inamount
as theamount
prop,pubkey
as thepariKey
prop, and aPositionSideEnum
for each side for theside
prop
The output should look similar to this:
Now, users can set position amounts and place positions for whichever side they choose, for the time interval that they selected, in the BTC-USD Devnet Parimutuel Market
Using it on Devnet
To use the app on devnet you will need Hxro issued devnet USDC token
How to:
Connect your wallet
Click the airdrop button on the right of the connect button
Click on USDC and you will get airdropped Hxro Devnet USDC that you can use to play with on your app!
Token Adress: DXSVQJqJbNTTcGqCkfHnQYXwG5GhZsfg2Ka9tNkK3ohr
Up Next
V2 of this Parimutuel UI Project Walkthrough with more functionalities from the Parimutuel TS SDK
Last updated