Skip to content
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
12 changes: 6 additions & 6 deletions components/ButtonGenerator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export default function ButtonGenerator (): JSX.Element {
<PayButtonWidget
key={`widget-${JSON.stringify(button)}`}
to={button.to}
amount={parseFloat(button.amount)}
amount={button.amount === '' ? undefined : parseFloat(button.amount)}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Inconsistent checks for amount and randomSatoshis logic.

Line 366 correctly parses amount to float for the widget. However, line 388's check button.amount !== '' is inconsistent with the UI visibility logic at line 325, which uses parseFloat(button.amount) > 0. This mismatch means that if a user enters "0" or "0.0", the randomSatoshis field won't be shown in the form (line 325 returns null), but the prop would still be passed to the component (line 388 would evaluate to true).

Consider aligning the check with the UI visibility logic:

-                  randomSatoshis={button.amount !== '' ? button.randomSatoshis : undefined}
+                  randomSatoshis={parseFloat(button.amount) > 0 ? button.randomSatoshis : undefined}

Also applies to: 388-388

🤖 Prompt for AI Agents
In components/ButtonGenerator/index.tsx around lines 325, 366 and 388, the
visibility logic uses parseFloat(button.amount) > 0 but the prop passing uses
button.amount !== '' which causes a mismatch for "0" values; update the prop
checks to mirror the UI logic by parsing the amount and only treating it as
present when parseFloat(amount) > 0, i.e. pass amount={parseFloat(button.amount)
> 0 ? parseFloat(button.amount) : undefined} and set randomSatoshis to be passed
only when parseFloat(button.amount) > 0 (handle NaN by treating non-numeric or
<=0 as absent), ensuring consistent behavior and guarding with Number.isFinite
or isNaN checks.

currency={button.currency}
text={button.text === '' ? undefined : button.text}
hoverText={
Expand All @@ -385,7 +385,7 @@ export default function ButtonGenerator (): JSX.Element {
? undefined
: button.onTransaction
}
randomSatoshis={button.randomSatoshis}
randomSatoshis={button.amount !== '' ? button.randomSatoshis : undefined}
hideToasts={button.hideToasts}
disableEnforceFocus={button.disableEnforceFocus}
contributionOffset={button.contributionOffset}
Expand All @@ -398,7 +398,7 @@ export default function ButtonGenerator (): JSX.Element {
<PayButton
key={`button-${JSON.stringify(button)}`}
to={button.to}
amount={button.amount}
amount={button.amount === '' ? undefined : button.amount}
currency={button.currency}
text={button.text === '' ? undefined : button.text}
hoverText={
Expand All @@ -420,16 +420,16 @@ export default function ButtonGenerator (): JSX.Element {
? undefined
: button.onTransaction
}
randomSatoshis={button.randomSatoshis}
randomSatoshis={button.amount !== '' ? button.randomSatoshis : undefined}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Inconsistent check for randomSatoshis (same as line 388).

The check button.amount !== '' is inconsistent with the UI visibility logic at line 325 (parseFloat(button.amount) > 0). This could cause the prop to be passed even when the form field is hidden (e.g., when amount is "0").

Apply the same fix as suggested for line 388:

-                  randomSatoshis={button.amount !== '' ? button.randomSatoshis : undefined}
+                  randomSatoshis={parseFloat(button.amount) > 0 ? button.randomSatoshis : undefined}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
randomSatoshis={button.amount !== '' ? button.randomSatoshis : undefined}
randomSatoshis={parseFloat(button.amount) > 0 ? button.randomSatoshis : undefined}
🤖 Prompt for AI Agents
In components/ButtonGenerator/index.tsx around line 423, the prop randomSatoshis
is conditionally passed using button.amount !== '' which is inconsistent with
the UI visibility check (parseFloat(button.amount) > 0); change the condition to
use parseFloat(button.amount) > 0 so randomSatoshis is only passed when the
numeric amount is greater than zero (i.e., replace the current check with the
same parseFloat(button.amount) > 0 guard used elsewhere).

hideToasts={button.hideToasts}
disableEnforceFocus={button.disableEnforceFocus}
contributionOffset={button.contributionOffset}
disableAltpayment={button.disableAltpayment}
disabled={button.disabled}
editable={button.editable}
autoClose={button.autoClose}
onOpen={button.onOpen}
onClose={button.onClose}
onOpen={button.onOpen === '' ? undefined : button.onOpen}
onClose={button.onClose === '' ? undefined : button.onClose}
wsBaseURL={button.wsBaseURL}
apiBaseURL={button.apiBaseURL}
/>
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@ chronik-client-cashtokens@^3.1.1-rc0:
dependencies:
"@types/ws" "^8.2.1"
axios "^1.6.3"
ecashaddrjs "file:../../../.cache/yarn/v6/npm-chronik-client-cashtokens-3.1.1-rc0-e5e4a3538e8010b70623974a731bf2712506c5e3-integrity/node_modules/ecashaddrjs"
ecashaddrjs "file:../.cache/yarn/v6/npm-chronik-client-cashtokens-3.1.1-rc0-e5e4a3538e8010b70623974a731bf2712506c5e3-integrity/node_modules/ecashaddrjs"
isomorphic-ws "^4.0.1"
protobufjs "^6.8.8"
ws "^8.3.0"
Expand Down Expand Up @@ -2830,7 +2830,7 @@ ecashaddrjs@^1.0.7:
big-integer "1.6.36"
bs58check "^3.0.1"

ecashaddrjs@^2.0.0, "ecashaddrjs@file:../.cache/yarn/v6/npm-chronik-client-cashtokens-3.1.1-rc0-e5e4a3538e8010b70623974a731bf2712506c5e3-integrity/node_modules/ecashaddrjs":
ecashaddrjs@^2.0.0, "ecashaddrjs@file:../../../.cache/yarn/v6/npm-chronik-client-cashtokens-3.1.1-rc0-e5e4a3538e8010b70623974a731bf2712506c5e3-integrity/node_modules/ecashaddrjs":
version "2.0.0"
resolved "https://registry.yarnpkg.com/ecashaddrjs/-/ecashaddrjs-2.0.0.tgz#d45ede7fb6168815dbcf664b8e0a6872e485d874"
integrity sha512-EvK1V4D3+nIEoD0ggy/b0F4lW39/72R9aOs/scm6kxMVuXu16btc+H74eQv7okNfXaQWKgolEekZkQ6wfcMMLw==
Expand Down