@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.
- package/README.md +96 -0
- package/bin/index.js +1123 -0
- package/package.json +44 -0
- package/templates/deps.json +29 -0
- package/templates/escrows/details/Actions.tsx +149 -0
- package/templates/escrows/details/Entities.tsx +48 -0
- package/templates/escrows/details/EntityCard.tsx +98 -0
- package/templates/escrows/details/EscrowDetailDialog.tsx +154 -0
- package/templates/escrows/details/GeneralInformation.tsx +329 -0
- package/templates/escrows/details/MilestoneCard.tsx +254 -0
- package/templates/escrows/details/MilestoneDetailDialog.tsx +276 -0
- package/templates/escrows/details/Milestones.tsx +87 -0
- package/templates/escrows/details/ProgressEscrow.tsx +191 -0
- package/templates/escrows/details/StatisticsCard.tsx +79 -0
- package/templates/escrows/details/SuccessReleaseDialog.tsx +101 -0
- package/templates/escrows/details/useDetailsEscrow.ts +126 -0
- package/templates/escrows/escrow-context/EscrowAmountProvider.tsx +86 -0
- package/templates/escrows/escrow-context/EscrowDialogsProvider.tsx +108 -0
- package/templates/escrows/escrow-context/EscrowProvider.tsx +124 -0
- package/templates/escrows/escrows-by-role/cards/EscrowsCards.tsx +503 -0
- package/templates/escrows/escrows-by-role/cards/Filters.tsx +421 -0
- package/templates/escrows/escrows-by-role/table/EscrowsTable.tsx +427 -0
- package/templates/escrows/escrows-by-role/table/Filters.tsx +421 -0
- package/templates/escrows/escrows-by-role/useEscrowsByRole.shared.ts +336 -0
- package/templates/escrows/escrows-by-signer/cards/EscrowsCards.tsx +502 -0
- package/templates/escrows/escrows-by-signer/cards/Filters.tsx +389 -0
- package/templates/escrows/escrows-by-signer/table/EscrowsTable.tsx +422 -0
- package/templates/escrows/escrows-by-signer/table/Filters.tsx +389 -0
- package/templates/escrows/escrows-by-signer/useEscrowsBySigner.shared.ts +320 -0
- package/templates/escrows/single-release/approve-milestone/button/ApproveMilestone.tsx +78 -0
- package/templates/escrows/single-release/approve-milestone/dialog/ApproveMilestone.tsx +102 -0
- package/templates/escrows/single-release/approve-milestone/form/ApproveMilestone.tsx +80 -0
- package/templates/escrows/single-release/approve-milestone/shared/schema.ts +9 -0
- package/templates/escrows/single-release/approve-milestone/shared/useApproveMilestone.ts +67 -0
- package/templates/escrows/single-release/change-milestone-status/button/ChangeMilestoneStatus.tsx +78 -0
- package/templates/escrows/single-release/change-milestone-status/dialog/ChangeMilestoneStatus.tsx +167 -0
- package/templates/escrows/single-release/change-milestone-status/form/ChangeMilestoneStatus.tsx +114 -0
- package/templates/escrows/single-release/change-milestone-status/shared/schema.ts +15 -0
- package/templates/escrows/single-release/change-milestone-status/shared/useChangeMilestoneStatus.ts +77 -0
- package/templates/escrows/single-release/dispute-escrow/button/DisputeEscrow.tsx +68 -0
- package/templates/escrows/single-release/fund-escrow/button/FundEscrow.tsx +84 -0
- package/templates/escrows/single-release/fund-escrow/dialog/FundEscrow.tsx +77 -0
- package/templates/escrows/single-release/fund-escrow/form/FundEscrow.tsx +54 -0
- package/templates/escrows/single-release/fund-escrow/shared/schema.ts +10 -0
- package/templates/escrows/single-release/fund-escrow/shared/useFundEscrow.ts +66 -0
- package/templates/escrows/single-release/initialize-escrow/dialog/InitializeEscrow.tsx +526 -0
- package/templates/escrows/single-release/initialize-escrow/form/InitializeEscrow.tsx +504 -0
- package/templates/escrows/single-release/initialize-escrow/shared/schema.ts +232 -0
- package/templates/escrows/single-release/initialize-escrow/shared/useInitializeEscrow.ts +115 -0
- package/templates/escrows/single-release/release-escrow/button/ReleaseEscrow.tsx +80 -0
- package/templates/escrows/single-release/resolve-dispute/button/ResolveDispute.tsx +94 -0
- package/templates/escrows/single-release/resolve-dispute/dialog/ResolveDispute.tsx +123 -0
- package/templates/escrows/single-release/resolve-dispute/form/ResolveDispute.tsx +82 -0
- package/templates/escrows/single-release/resolve-dispute/shared/schema.ts +82 -0
- package/templates/escrows/single-release/resolve-dispute/shared/useResolveDispute.ts +58 -0
- package/templates/escrows/single-release/update-escrow/dialog/UpdateEscrow.tsx +485 -0
- package/templates/escrows/single-release/update-escrow/form/UpdateEscrow.tsx +463 -0
- package/templates/escrows/single-release/update-escrow/shared/schema.ts +139 -0
- package/templates/escrows/single-release/update-escrow/shared/useUpdateEscrow.ts +211 -0
- package/templates/handle-errors/errors.enum.ts +6 -0
- package/templates/handle-errors/handle.ts +47 -0
- package/templates/helpers/format.helper.ts +27 -0
- package/templates/helpers/useCopy.ts +13 -0
- package/templates/providers/ReactQueryClientProvider.tsx +28 -0
- package/templates/providers/TrustlessWork.tsx +30 -0
- package/templates/tanstak/useEscrowsByRoleQuery.ts +87 -0
- package/templates/tanstak/useEscrowsBySignerQuery.ts +78 -0
- package/templates/tanstak/useEscrowsMutations.ts +411 -0
- package/templates/wallet-kit/WalletButtons.tsx +116 -0
- package/templates/wallet-kit/WalletProvider.tsx +94 -0
- package/templates/wallet-kit/trustlines.ts +40 -0
- package/templates/wallet-kit/useWallet.ts +77 -0
- package/templates/wallet-kit/validators.ts +12 -0
- 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,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
|
+
};
|