Skip to content

Commit

Permalink
fix: pass in neccessary params + update form
Browse files Browse the repository at this point in the history
  • Loading branch information
beesaferoot committed Nov 8, 2024
1 parent 2c323ae commit e331ccb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
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

0 comments on commit e331ccb

Please sign in to comment.