Skip to content

Commit

Permalink
Merge pull request #42 from gnosischain/dev
Browse files Browse the repository at this point in the history
fix: amount treshold below 1 GNO
  • Loading branch information
Wagalidoom authored May 30, 2024
2 parents 3e6117f + 2a1b3b5 commit 68da8a1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deposits_data_cronjob.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
notify:
uses: ./.github/workflows/slack_release_notification.yml
if: ${{ always() }}
needs: [ deploy ]
needs: deploy
secrets:
RELEASES_SLACK_WEBHOOK_URL: ${{ secrets.RELEASES_SLACK_WEBHOOK_URL }}
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prod_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
notify:
uses: ./.github/workflows/slack_release_notification.yml
if: ${{ always() }}
needs: [ deploy ]
needs: deploy
secrets:
RELEASES_SLACK_WEBHOOK_URL: ${{ secrets.RELEASES_SLACK_WEBHOOK_URL }}
with:
Expand Down
19 changes: 8 additions & 11 deletions components/withdrawal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function Withdrawal() {
const { claim, claimBalance, claimSuccess, claimHash } = useClaimBalance();
const { register, updateConfig, unregister, isRegister, autoclaimSuccess, autoclaimHash, chainId } = useAutoclaim();
const [timeValue, setTimeValue] = useState(1);
const [amountValue, setAmountValue] = useState(1);
const [amountValue, setAmountValue] = useState("1");
const [step, setStep] = useState("claim");
const [tx, setTx] = useState<Address>("0x0");
const [loading, setLoading] = useState(false);
Expand All @@ -20,21 +20,18 @@ export default function Withdrawal() {
};

const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const newAmount = parseFloat(event.target.value);
if (newAmount <= 0) {
setAmountValue(1);
} else {
setAmountValue(newAmount);
}
const inputVal = event.target.value;
setAmountValue(inputVal);
};

const onAutoclaim = useCallback(async () => {
if (!isNaN(amountValue) && amountValue > 0) {
const parsedValue = parseFloat(amountValue.replace(/,/, "."));
if (!isNaN(parsedValue) && parsedValue > 0) {
setLoading(true);
if (isRegister) {
await updateConfig(timeValue, amountValue);
await updateConfig(timeValue, parsedValue);
} else {
await register(timeValue, amountValue);
await register(timeValue, parsedValue);
}
}
}, [timeValue, amountValue, isRegister, register, updateConfig]);
Expand Down Expand Up @@ -104,7 +101,7 @@ export default function Withdrawal() {
<label htmlFor="default-input" className="block mb-2 text-xs font-bold text-gray-700">
Amount threshold
</label>
<input type="number" value={amountValue} onChange={handleInputChange} id="default-input" className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-full p-1" />
<input type="text" value={amountValue.toString()} onChange={handleInputChange} id="default-input" className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-full p-1" />
</div>
<button className="bg-[#DD7143] py-1 rounded-full text-white text-lg font-semibold" onClick={onAutoclaim}>
{isRegister ? "Update" : "Register"}
Expand Down
5 changes: 3 additions & 2 deletions hooks/use-autoclaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import claimRegistryABI from "@/utils/abis/claimRegistry";
import { getPublicClient } from "wagmi/actions";
import { config } from "@/wagmi";
import { fetchRegister, fetchUnregister } from "@/utils/fetchEvents";
import { parseUnits } from "viem";

function useAutoclaim() {
const account = useAccount();
Expand Down Expand Up @@ -47,7 +48,7 @@ function useAutoclaim() {
async (days: number, amount: number) => {
if (contractConfig) {
const timeStamp = BigInt(days * 86400000);
writeContract({ address: contractConfig.addresses.claimRegistry, abi: claimRegistryABI, functionName: "register", args: [account.address || "0x0", timeStamp, BigInt(amount)] });
writeContract({ address: contractConfig.addresses.claimRegistry, abi: claimRegistryABI, functionName: "register", args: [account.address || "0x0", timeStamp, parseUnits(amount.toString(), 18)] });
}
},
[account]
Expand All @@ -57,7 +58,7 @@ function useAutoclaim() {
async (days: number, amount: number) => {
if (contractConfig) {
const timeStamp = BigInt(days * 86400000);
writeContract({ address: contractConfig.addresses.claimRegistry, abi: claimRegistryABI, functionName: "updateConfig", args: [account.address || "0x0", timeStamp, BigInt(amount)] });
writeContract({ address: contractConfig.addresses.claimRegistry, abi: claimRegistryABI, functionName: "updateConfig", args: [account.address || "0x0", timeStamp, parseUnits(amount.toString(), 18)] });
}
},
[account]
Expand Down

0 comments on commit 68da8a1

Please sign in to comment.