Skip to content

feat: Simulate what auto-bet would do#6

Open
underyx wants to merge 2 commits into
Frostwork-Media:Working-branchfrom
underyx:main
Open

feat: Simulate what auto-bet would do#6
underyx wants to merge 2 commits into
Frostwork-Media:Working-branchfrom
underyx:main

Conversation

@underyx
Copy link
Copy Markdown

@underyx underyx commented Dec 7, 2023

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.)

@vercel
Copy link
Copy Markdown

vercel Bot commented Dec 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
market-transfer ❌ Failed (Inspect) Dec 7, 2023 6:38am

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');
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I could tell this was loading the stored key from the wrong key (we were setting it in manifold elsewhere)

Comment thread components/AutomateBettingForm.tsx Outdated
} else if (storedtableData) {
setProcessedData(storedtableData);
}
}, []);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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} />
Copy link
Copy Markdown
Author

@underyx underyx Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyName: string;
defaultKey?: string;
onChange?: (key: string) => void;
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}
Copy link
Copy Markdown
Author

@underyx underyx Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread components/ApiKeyInput.tsx Outdated

useEffect(() => {
window.localStorage.setItem(keyName, apiKey);
}, [apiKey, keyName]);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@underyx underyx changed the base branch from main to Working-branch December 7, 2023 06:23
Comment thread components/AutomateBettingForm.tsx Outdated
@Nathanpmyoung
Copy link
Copy Markdown
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants