forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContractForm.tsx
More file actions
61 lines (52 loc) · 1.65 KB
/
Copy pathContractForm.tsx
File metadata and controls
61 lines (52 loc) · 1.65 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
import { Alert, Card, Text } from "@stellar/design-system";
import { contract } from "@stellar/stellar-sdk";
import { Box } from "../../components/layout/Box";
import { InvokeContractForm } from "./InvokeContractForm";
import { useWallet } from "../../hooks/useWallet";
export const ContractForm = ({
contractClient,
contractClientError,
}: {
contractClient: contract.Client;
contractClientError: Error | null;
}) => {
const { address: userPk } = useWallet();
const contractSpecFuncs = contractClient.spec?.funcs();
const renderFunctionCard = () =>
contractSpecFuncs
?.filter((func) => !func.name().toString().includes("__"))
?.map((func) => {
const funcName = func.name().toString();
return (
<InvokeContractForm
key={funcName}
funcName={funcName}
contractClient={contractClient}
/>
);
});
const renderError = () => (
<Alert variant="error" placement="inline" title="Error">
{contractClientError?.message}
</Alert>
);
return (
<Box gap="md">
{!userPk ? (
<Alert variant="warning" placement="inline" title="Connect wallet">
A connected wallet is required to invoke this contract. Please connect
your wallet to proceed.
</Alert>
) : null}
<Card variant="secondary">
<Box gap="lg" data-testid="invoke-contract-container">
<Text as="h2" size="md" weight="semi-bold">
Invoke Contract
</Text>
{contractSpecFuncs ? renderFunctionCard() : null}
{contractClientError ? renderError() : null}
</Box>
</Card>
</Box>
);
};