Skip to content

Commit

Permalink
Merge branch 'develop' into style-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Luigy-Lemon authored Dec 19, 2023
2 parents 404a61b + 3454bc2 commit 7f3580d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/components/ActionButton/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface IActionButtonProps {
method: string;
mutationData?: WriteContractResult;
mutationTrigger?: () => void;
isDenied: boolean;

// TODO: Import this type? Define it dynamically somehow?
onSettled?: (
Expand All @@ -21,22 +22,24 @@ const ActionButton: React.FC<IActionButtonProps> = ({
mutationTrigger,
mutationData,
onSettled,
isDenied,
}) => {
const { data, error } = useWaitForTransaction({
confirmations: 1,
hash: mutationData?.hash,
});

useEffect(
() => mutationData?.hash && onSettled?.(mutationData.hash, data, error),
[onSettled, mutationData?.hash, data, error]
);
if (!isDenied) {
const { data, error } = useWaitForTransaction({
confirmations: 1,
hash: mutationData?.hash,
});
useEffect(
() => mutationData?.hash && onSettled?.(mutationData.hash, data, error),
[onSettled, mutationData?.hash, data, error]
);
}

return (
// <div className="full-width">
<button
className="border rounded-md w-full bg-[#DD7143] hover:border-[#DD7143] active:opacity-90 p-4 my-1 text-[#fff] text-center font-semibold text-xl "
onClick={() => mutationTrigger?.()}
className="border rounded-md w-full bg-[#FFC549] hover:border-[#FFC549] active:opacity-90 p-4 my-1 text-[#1C352A] text-center font-semibold text-xl "
onClick={() => { isDenied ? console.error('Action failed') : mutationTrigger?.()}}
>
{method}
</button>
Expand Down
2 changes: 2 additions & 0 deletions src/components/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const Form: React.FC = () => {
sharesBalance: state.sharesBalance,
depositAllowance: state.depositAllowance,
withdrawAllowance: state.withdrawAllowance,
isDenied: state.isDenied,
})),
true,
);
Expand Down Expand Up @@ -279,6 +280,7 @@ const Form: React.FC = () => {
mutationTrigger={method.write}
mutationData={method.data}
onSettled={onSettled}
isDenied={account.isDenied}
/>
</div>

Expand Down
9 changes: 9 additions & 0 deletions src/stores/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface AccountStore {
setAddress: (address: `0x${string}`) => Promise<void>;
fetch: () => Promise<void>;
watch: () => void;
isDenied: boolean;
}

export interface AccountStoreLoaded extends AccountStore {
Expand All @@ -55,9 +56,17 @@ export type AnyAccountStore = AccountStoreLoaded | AccountStoreLoading | Account

export const useAccountStore = create<AnyAccountStore>((set, get) => ({
address: undefined,
isDenied: false,
loading: false,
setAddress: async (address: `0x${string}`) => {
set({ address, loading: true });
try {
const response = await fetch(`https://sdai-api.dev.gnosisdev.com/api/v1/denylist/${address}`);
const data = await response.json();
set({ isDenied: data.denied });
} catch (error) {
set({ isDenied: false });
}
return get().fetch();
},
fetch: async () => {
Expand Down

0 comments on commit 7f3580d

Please sign in to comment.