-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallowanceReceiver.js
More file actions
70 lines (64 loc) · 2 KB
/
allowanceReceiver.js
File metadata and controls
70 lines (64 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { useEffect, useState } from "react";
import { connect } from "react-redux";
import { updateUserAllowance } from "../store/actions/wallet";
import { notify } from "reapop";
import Link from "next/link";
import { useApiClient } from "../context/ApiClientContext";
function AllowanceReceiver(props) {
const [loading, setLoading] = useState(false);
const [isBalanceLow, setIsBalanceLow] = useState(
Number(props.balance) <= 500 && Number(props.allowance) <= 500
);
const { cosmosFeegrantApiClient } = useApiClient();
useEffect(() => {
setIsBalanceLow(
Number(props.balance) <= 500 && Number(props.allowance) <= 500
);
}, [props.balance, props.allowance]);
const checkAllowance = async () => {
if (loading) return;
if (!props.selectedAddress) {
props.notify("Please sign in before claiming tokens", "error");
return;
}
setLoading(true);
await props.updateUserAllowance(cosmosFeegrantApiClient);
setLoading(false);
};
return isBalanceLow ? (
<div className="mb-8">
<div className="bg-box-grad-tl bg-base-200 p-4 rounded-md mb-4">
<div>
<div className="text-lg">Get Fee Grant</div>
<div className="text-xs mt-2 text-type-secondary">
You can ask for a fee grant to start using Gitopia without buying
any {(process.env.NEXT_PUBLIC_CURRENCY_TOKEN || "").toUpperCase()}
</div>
</div>
<div className="mt-4">
<Link
className={"btn btn-sm btn-primary btn-wide"}
href="/login?step=5"
rel="noreferrer"
>
Request Grant
</Link>
</div>
</div>
</div>
) : (
""
);
}
const mapStateToProps = (state) => {
return {
selectedAddress: state.wallet.selectedAddress,
allowance: state.wallet.allowance,
balance: state.wallet.balance,
advanceUser: state.user.advanceUser,
};
};
export default connect(mapStateToProps, {
updateUserAllowance,
notify,
})(AllowanceReceiver);