Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass in neccessary params + update form #38

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions website/src/app/Components/HomeComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ const HomeComponent: React.FC = () => {
const [startingCode, setStartingCode] = useState<number | null>(null)
const [privateKey, setPrivateKey] = useState<string>("")
const [selectedCommand, setSelectedCommand] = useState<string>("1")
const [commandArgument, setCommandArgument] = useState<number>(7)
const [commandArgument, setCommandArgument] = useState<number>()
const [result, setResult] = useState<TokenData | null>(null)
const [error, setError] = useState<string | null>(null)

const commandOptions: CommandOptions = {
"1": { name: "add_time - Add PAYG time", requiresArgument: true },
"2": { name: "set_time - Set PAYG time", requiresArgument: true },
"3": { name: "disable_payg - Disable PAYG", requiresArgument: false },
"4": { name: "counter_sync - Counter sync", requiresArgument: true },
"4": { name: "counter_sync - Counter sync", requiresArgument: false },
}

const handleSubmit = async (
Expand All @@ -39,10 +39,6 @@ const HomeComponent: React.FC = () => {
e.preventDefault()
setError(null)

if (!serialNumber) {
setError("Serial number is required")
return
}
if (counter === null || isNaN(counter)) {
setError("Counter must be a valid number")
return
Expand All @@ -64,12 +60,12 @@ const HomeComponent: React.FC = () => {
const encoder = new Encoder()
try {
const { finalToken, newCount } = encoder.generateToken({
tokenType: 1,
tokenType: parseInt(selectedCommand),
secretKeyHex: privateKey,
count: counter,
startingCode: startingCode,
restrictDigitSet: false,
value: 1,
value: commandArgument,
extendToken: false,
})

Expand Down Expand Up @@ -101,7 +97,7 @@ const HomeComponent: React.FC = () => {
htmlFor="serialNumber"
className="block text-sm font-bold text-gray-700"
>
Serial number:
Serial number (Optional):
</label>
<input
type="text"
Expand All @@ -110,7 +106,6 @@ const HomeComponent: React.FC = () => {
value={serialNumber}
onChange={(e) => setSerialNumber(e.target.value)}
placeholder="ex: HQ1932ER3DF"
required
/>
</div>
<div className="mb-4">
Expand Down Expand Up @@ -205,7 +200,7 @@ const HomeComponent: React.FC = () => {
htmlFor="commandArgument"
className="block text-sm font-bold text-gray-700"
>
Command argument:
Activation days:
</label>
<input
type="number"
Expand All @@ -230,36 +225,36 @@ const HomeComponent: React.FC = () => {
{error && <p className="text-red-500">{error}</p>}
{result && (
<div className="mt-4">
<h2 className="font-bold">Result:</h2>
<h2 className="font-bold text-black">Result:</h2>
<table className="min-w-full border border-gray-300 mt-2">
<thead>
<tr className="bg-gray-100">
<th className="border border-gray-300 px-4 py-2">
<th className="border border-gray-300 px-4 py-2 text-gray-700">
Serial
</th>
<th className="border border-gray-300 px-4 py-2">
<th className="border border-gray-300 px-4 py-2 text-gray-700">
Command
</th>
<th className="border border-gray-300 px-4 py-2">
<th className="border border-gray-300 px-4 py-2 text-gray-700">
Token
</th>
<th className="border border-gray-300 px-4 py-2">
<th className="border border-gray-300 px-4 py-2 text-gray-700">
Counter
</th>
</tr>
</thead>
<tbody>
<tr>
<td className="border border-gray-300 px-4 py-2">
<td className="border border-gray-300 px-4 py-2 text-black">
{serialNumber}
</td>
<td className="border border-gray-300 px-4 py-2">
<td className="border border-gray-300 px-4 py-2 text-black">
{commandOptions[selectedCommand].name}
</td>
<td className="border border-gray-300 px-4 py-2">
<td className="border border-gray-300 px-4 py-2 text-black">
{result.finalToken || "N/A"}
</td>
<td className="border border-gray-300 px-4 py-2">
<td className="border border-gray-300 px-4 py-2 text-black">
{result.newCount || "N/A"}
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion website/src/app/Components/openpaygo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare module "openpaygo" {
count: number
startingCode: number
restrictDigitSet: boolean
value: number
value: number | undefined
extendToken: boolean
}): { finalToken: string; newCount: number }
}
Expand Down
Loading