feat: Simulate what auto-bet would do#6
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| console.log("Stored user data", storedUserData); | ||
| console.log("Stored user data was", storedUserData); | ||
| const storedProcessedData = JSON.parse(window.localStorage.getItem('processed-data')); | ||
| const storedApiKey = window.localStorage.getItem('api-key'); |
There was a problem hiding this comment.
as far as I could tell this was loading the stored key from the wrong key (we were setting it in manifold elsewhere)
| } else if (storedtableData) { | ||
| setProcessedData(storedtableData); | ||
| } | ||
| }, []); |
There was a problem hiding this comment.
this seemed to be nearly the same as the useEffect above (only difference was in logging) so I removed it
| <label htmlFor="api-key" className="block text-sm font-medium text-gray-700">API key (for auto betting, leave empty for simulation mode)</label> | ||
|
|
||
| <ApiKeyInput keyName="manifold" /> | ||
| <ApiKeyInput keyName="manifold" onChange={setApiKey} /> |
There was a problem hiding this comment.
We're now passing this component's state setter to the input field so that this component can react to changes to the value immediately. I wanted to add this behavior so that simulated rows can be cleared by typing in the API key field.
There was a problem hiding this comment.
See why this file was changed here: https://github.com/Frostwork-Media/market-transfer/pull/6/files#r1418426527
| keyName: string; | ||
| defaultKey?: string; | ||
| onChange?: (key: string) => void; | ||
| } |
There was a problem hiding this comment.
Added this definition just to make coding easier; TypeScript can now verify the correct parameters are being passed in to the function.
| const handleAPIKeyChange = (event) => { | ||
| setApiKey(event.target.value); | ||
| }; | ||
| export default function Component({ keyName, defaultKey = "", onChange = () => null }: Props) { |
There was a problem hiding this comment.
I set () => null as a default value for onChange which means by default, for instance for the database key, nothing is done.
| className="block w-full mt-1 border border-gray-200 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm" | ||
| value={apiKey} | ||
| onChange={handleAPIKeyChange} | ||
| defaultValue={defaultApiKey} |
There was a problem hiding this comment.
Switch to using defaultValue instead of value because the latter would require that we write code that keeps the value up-to-date; otherwise the browser would not update the text it shows in the field. This change made it possible to remove the useState call above.
|
|
||
| useEffect(() => { | ||
| window.localStorage.setItem(keyName, apiKey); | ||
| }, [apiKey, keyName]); |
There was a problem hiding this comment.
I removed this along with all Input component state management in favor of the Form tracking all API key changes, so that the form can immediately react to keypresses. I think previous behavior was that the key would be saved in local storage but you needed to refresh the page to re-trigger the form's getItem call; this way a refresh is no longer needed.
Note however that the database key will no longer be set in local storage. I think that's fine though as I saw no usages of that value.
|
Hey @underyx, I am not very good at coding and this is kind of a starter project for me. I have a friend helping and we'll try and tidy it up. I'm sorry if that's wasted any of your time. |
Was curious what the app was but didn't want to put in my API key without knowing. I changed the code to be interactable even without an API key. Maybe this will even be useful for real users to see ahead of time what the Autobet button would do (especially if the devs will keep updating behavior.)