@trustless-work/blocks 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +96 -0
  2. package/bin/index.js +1123 -0
  3. package/package.json +44 -0
  4. package/templates/deps.json +29 -0
  5. package/templates/escrows/details/Actions.tsx +149 -0
  6. package/templates/escrows/details/Entities.tsx +48 -0
  7. package/templates/escrows/details/EntityCard.tsx +98 -0
  8. package/templates/escrows/details/EscrowDetailDialog.tsx +154 -0
  9. package/templates/escrows/details/GeneralInformation.tsx +329 -0
  10. package/templates/escrows/details/MilestoneCard.tsx +254 -0
  11. package/templates/escrows/details/MilestoneDetailDialog.tsx +276 -0
  12. package/templates/escrows/details/Milestones.tsx +87 -0
  13. package/templates/escrows/details/ProgressEscrow.tsx +191 -0
  14. package/templates/escrows/details/StatisticsCard.tsx +79 -0
  15. package/templates/escrows/details/SuccessReleaseDialog.tsx +101 -0
  16. package/templates/escrows/details/useDetailsEscrow.ts +126 -0
  17. package/templates/escrows/escrow-context/EscrowAmountProvider.tsx +86 -0
  18. package/templates/escrows/escrow-context/EscrowDialogsProvider.tsx +108 -0
  19. package/templates/escrows/escrow-context/EscrowProvider.tsx +124 -0
  20. package/templates/escrows/escrows-by-role/cards/EscrowsCards.tsx +503 -0
  21. package/templates/escrows/escrows-by-role/cards/Filters.tsx +421 -0
  22. package/templates/escrows/escrows-by-role/table/EscrowsTable.tsx +427 -0
  23. package/templates/escrows/escrows-by-role/table/Filters.tsx +421 -0
  24. package/templates/escrows/escrows-by-role/useEscrowsByRole.shared.ts +336 -0
  25. package/templates/escrows/escrows-by-signer/cards/EscrowsCards.tsx +502 -0
  26. package/templates/escrows/escrows-by-signer/cards/Filters.tsx +389 -0
  27. package/templates/escrows/escrows-by-signer/table/EscrowsTable.tsx +422 -0
  28. package/templates/escrows/escrows-by-signer/table/Filters.tsx +389 -0
  29. package/templates/escrows/escrows-by-signer/useEscrowsBySigner.shared.ts +320 -0
  30. package/templates/escrows/single-release/approve-milestone/button/ApproveMilestone.tsx +78 -0
  31. package/templates/escrows/single-release/approve-milestone/dialog/ApproveMilestone.tsx +102 -0
  32. package/templates/escrows/single-release/approve-milestone/form/ApproveMilestone.tsx +80 -0
  33. package/templates/escrows/single-release/approve-milestone/shared/schema.ts +9 -0
  34. package/templates/escrows/single-release/approve-milestone/shared/useApproveMilestone.ts +67 -0
  35. package/templates/escrows/single-release/change-milestone-status/button/ChangeMilestoneStatus.tsx +78 -0
  36. package/templates/escrows/single-release/change-milestone-status/dialog/ChangeMilestoneStatus.tsx +167 -0
  37. package/templates/escrows/single-release/change-milestone-status/form/ChangeMilestoneStatus.tsx +114 -0
  38. package/templates/escrows/single-release/change-milestone-status/shared/schema.ts +15 -0
  39. package/templates/escrows/single-release/change-milestone-status/shared/useChangeMilestoneStatus.ts +77 -0
  40. package/templates/escrows/single-release/dispute-escrow/button/DisputeEscrow.tsx +68 -0
  41. package/templates/escrows/single-release/fund-escrow/button/FundEscrow.tsx +84 -0
  42. package/templates/escrows/single-release/fund-escrow/dialog/FundEscrow.tsx +77 -0
  43. package/templates/escrows/single-release/fund-escrow/form/FundEscrow.tsx +54 -0
  44. package/templates/escrows/single-release/fund-escrow/shared/schema.ts +10 -0
  45. package/templates/escrows/single-release/fund-escrow/shared/useFundEscrow.ts +66 -0
  46. package/templates/escrows/single-release/initialize-escrow/dialog/InitializeEscrow.tsx +526 -0
  47. package/templates/escrows/single-release/initialize-escrow/form/InitializeEscrow.tsx +504 -0
  48. package/templates/escrows/single-release/initialize-escrow/shared/schema.ts +232 -0
  49. package/templates/escrows/single-release/initialize-escrow/shared/useInitializeEscrow.ts +115 -0
  50. package/templates/escrows/single-release/release-escrow/button/ReleaseEscrow.tsx +80 -0
  51. package/templates/escrows/single-release/resolve-dispute/button/ResolveDispute.tsx +94 -0
  52. package/templates/escrows/single-release/resolve-dispute/dialog/ResolveDispute.tsx +123 -0
  53. package/templates/escrows/single-release/resolve-dispute/form/ResolveDispute.tsx +82 -0
  54. package/templates/escrows/single-release/resolve-dispute/shared/schema.ts +82 -0
  55. package/templates/escrows/single-release/resolve-dispute/shared/useResolveDispute.ts +58 -0
  56. package/templates/escrows/single-release/update-escrow/dialog/UpdateEscrow.tsx +485 -0
  57. package/templates/escrows/single-release/update-escrow/form/UpdateEscrow.tsx +463 -0
  58. package/templates/escrows/single-release/update-escrow/shared/schema.ts +139 -0
  59. package/templates/escrows/single-release/update-escrow/shared/useUpdateEscrow.ts +211 -0
  60. package/templates/handle-errors/errors.enum.ts +6 -0
  61. package/templates/handle-errors/handle.ts +47 -0
  62. package/templates/helpers/format.helper.ts +27 -0
  63. package/templates/helpers/useCopy.ts +13 -0
  64. package/templates/providers/ReactQueryClientProvider.tsx +28 -0
  65. package/templates/providers/TrustlessWork.tsx +30 -0
  66. package/templates/tanstak/useEscrowsByRoleQuery.ts +87 -0
  67. package/templates/tanstak/useEscrowsBySignerQuery.ts +78 -0
  68. package/templates/tanstak/useEscrowsMutations.ts +411 -0
  69. package/templates/wallet-kit/WalletButtons.tsx +116 -0
  70. package/templates/wallet-kit/WalletProvider.tsx +94 -0
  71. package/templates/wallet-kit/trustlines.ts +40 -0
  72. package/templates/wallet-kit/useWallet.ts +77 -0
  73. package/templates/wallet-kit/validators.ts +12 -0
  74. package/templates/wallet-kit/wallet-kit.ts +30 -0
@@ -0,0 +1,77 @@
1
+ import { kit } from "./wallet-kit";
2
+ import { useWalletContext } from "./WalletProvider";
3
+ import { ISupportedWallet } from "@creit.tech/stellar-wallets-kit";
4
+
5
+ /**
6
+ * Custom hook that provides wallet connection and disconnection functionality
7
+ * Integrates with the Stellar Wallet Kit and manages wallet state through context
8
+ */
9
+ export const useWallet = () => {
10
+ // Get wallet management functions from the context
11
+ const { setWalletInfo, clearWalletInfo } = useWalletContext();
12
+
13
+ /**
14
+ * Connect to a Stellar wallet using the Wallet Kit
15
+ * Opens a modal for wallet selection and handles the connection process
16
+ * Automatically sets wallet information in the context upon successful connection
17
+ */
18
+ const connectWallet = async () => {
19
+ await kit.openModal({
20
+ modalTitle: "Connect to your favorite wallet",
21
+ onWalletSelected: async (option: ISupportedWallet) => {
22
+ // Set the selected wallet as the active wallet
23
+ kit.setWallet(option.id);
24
+
25
+ // Get the wallet address and name
26
+ const { address } = await kit.getAddress();
27
+ const { name } = option;
28
+
29
+ // Store wallet information in the context and localStorage
30
+ setWalletInfo(address, name);
31
+ },
32
+ });
33
+ };
34
+
35
+ /**
36
+ * Disconnect from the current wallet
37
+ * Clears wallet information from the context and localStorage
38
+ * Disconnects the wallet from the Stellar Wallet Kit
39
+ */
40
+ const disconnectWallet = async () => {
41
+ await kit.disconnect();
42
+ clearWalletInfo();
43
+ };
44
+
45
+ /**
46
+ * Handle wallet connection with error handling
47
+ * Wraps the connectWallet function in a try-catch block for better error management
48
+ */
49
+ const handleConnect = async () => {
50
+ try {
51
+ await connectWallet();
52
+ } catch (error) {
53
+ console.error("Error connecting wallet:", error);
54
+ // You can add additional error handling here, such as showing user notifications
55
+ }
56
+ };
57
+
58
+ /**
59
+ * Handle wallet disconnection with error handling
60
+ * Wraps the disconnectWallet function in a try-catch block for better error management
61
+ */
62
+ const handleDisconnect = async () => {
63
+ try {
64
+ await disconnectWallet();
65
+ } catch (error) {
66
+ console.error("Error disconnecting wallet:", error);
67
+ // You can add additional error handling here, such as showing user notifications
68
+ }
69
+ };
70
+
71
+ return {
72
+ connectWallet,
73
+ disconnectWallet,
74
+ handleConnect,
75
+ handleDisconnect,
76
+ };
77
+ };
@@ -0,0 +1,12 @@
1
+ export const isValidWallet = (wallet: string) => {
2
+ if (wallet.length !== 56 || wallet[0] !== "G") {
3
+ return false;
4
+ }
5
+
6
+ const base32Regex = /^[A-Z2-7]+$/;
7
+ if (!base32Regex.test(wallet)) {
8
+ return false;
9
+ }
10
+
11
+ return true;
12
+ };
@@ -0,0 +1,30 @@
1
+ import {
2
+ StellarWalletsKit,
3
+ WalletNetwork,
4
+ FREIGHTER_ID,
5
+ AlbedoModule,
6
+ FreighterModule,
7
+ } from "@creit.tech/stellar-wallets-kit";
8
+
9
+ export const kit: StellarWalletsKit = new StellarWalletsKit({
10
+ network: WalletNetwork.TESTNET,
11
+ selectedWalletId: FREIGHTER_ID,
12
+ modules: [new FreighterModule(), new AlbedoModule()],
13
+ });
14
+
15
+ interface SignTransactionParams {
16
+ unsignedTransaction: string;
17
+ address: string;
18
+ }
19
+
20
+ export const signTransaction = async ({
21
+ unsignedTransaction,
22
+ address,
23
+ }: SignTransactionParams): Promise<string> => {
24
+ const { signedTxXdr } = await kit.signTransaction(unsignedTransaction, {
25
+ address,
26
+ networkPassphrase: WalletNetwork.TESTNET,
27
+ });
28
+
29
+ return signedTxXdr;
30
+ };