diff --git a/src/handlers/handlers.ts b/src/handlers/handlers.ts index 03254e448bd3f1ecf26972e7ad9de1547b30728d..c0a5a3fc87cda5680bcc7c1d194bbd764b4ba5b9 100644 --- a/src/handlers/handlers.ts +++ b/src/handlers/handlers.ts @@ -7,10 +7,13 @@ import { askQuestion } from '../utils/askQuestion.js'; // IMPORT TYPES import { Association } from '../types/Association.js'; +import { Proposal } from '../types/Proposal.js'; // IMPORT SERVICES import { getBalance } from '../services/balance.service.js'; -import { createAssociation } from '../services/association.service.js'; +import { createAssociation, joinAssociation } from '../services/association.service.js'; +import { createProposal } from '../services/proposal.service.js'; +import { createFA21Contract } from '../services/contract.service.js'; async function handleCreateAsssociation(tezos: TezosToolkit) { const name = await askQuestion(chalk.yellow('Nom: ')); @@ -20,34 +23,66 @@ async function handleCreateAsssociation(tezos: TezosToolkit) { description: description }; - console.log("Création du token en cours..."); + console.log("Création de l'association en cours..."); try { const op = await createAssociation(association, tezos); console.log(op.hash); console.log(chalk.green("\nVotre association a été crée !!\n")); } catch { - console.log("Erreur lors de la création du token"); + console.log("Erreur lors de la création de l'association"); } } async function handleCreateToken(tezos: TezosToolkit) { - const nbTokenFungible = await askQuestion(chalk.yellow('Nombre de token fongible: ')); - // Faire le call pour créer un token - console.log(chalk.green("\nVotre token a été créé !!\n")); + const nbTokenFungible: string = await askQuestion(chalk.yellow('Nombre de token fongible: ')); + + try { + const op = await createFA21Contract(nbTokenFungible, tezos); + console.log(op.hash); + console.log(chalk.green("\nVotre token a été créé !!\n")); + } catch { + console.log("Erreur lors de la création du token"); + } } async function handleGetBalance(tezos: TezosToolkit) { - const balance = await getBalance(tezos); - console.log(`\nSolde du portefeuille: ${balance} ꜩ\n`); + try { + const balance = await getBalance(tezos); + console.log(`\nSolde du portefeuille: ${balance} ꜩ\n`); + } catch { + console.log("Erreur lors de la récupération de votre portefeuille"); + } } async function handleCreateProposal(tezos: TezosToolkit) { + const title = await askQuestion(chalk.yellow('Titre: ')); + const description = await askQuestion(chalk.yellow('Description: ')); + const proposal: Proposal = { + title: title, + description: description + }; + + try { + console.log("Création de la proposition en cours..."); + const op = await createProposal(proposal, tezos); + console.log(op.hash); console.log(chalk.green("\nVous avez soumis une proposition !!\n")); - // Faire l'appel a post proposal association + } catch { + console.log("Erreur lors de la création de la proposition"); + } } async function handleJoinAssociation(tezos: TezosToolkit) { - const name = await askQuestion(chalk.yellow("Nom de l'association: ")); + const name = await askQuestion(chalk.yellow("Nom de l'association: ")); + + try { + console.log("Inscription à l'association en cours..."); + const op = await joinAssociation(name, tezos); + console.log(op.hash); + console.log(chalk.green("\nVous avez soumis une proposition !!\n")); + } catch { + console.log("Erreur lors de l'inscription à l'association"); + } console.log(chalk.green("\nVous avez rejoint l'association !!\n")); } diff --git a/src/services/contract.service.ts b/src/services/contract.service.ts index 4854546926a59dbe1de5897a0725a23a2cec759e..291b430033b5b75453fa7a2a9b21ea745055a9ca 100644 --- a/src/services/contract.service.ts +++ b/src/services/contract.service.ts @@ -4,9 +4,9 @@ import { Operation, TezosToolkit } from '@taquito/taquito'; const address = "KT1QZJzhSPQ89K4eC59tmQYCt44qph7wXoJu" // NEED UPDATE ENTRYPOINT !! -async function createFA21Contract(tezos: TezosToolkit): Promise<Operation> { +async function createFA21Contract(nbTokenFongible: string, tezos: TezosToolkit): Promise<Operation> { const contract = await tezos.contract.at(address); - const op: Operation = await contract.methodsObject.createFA21Contract().send(); + const op: Operation = await contract.methodsObject.createFA21Contract(nbTokenFongible).send(); await op.confirmation(); return op; diff --git a/src/services/index.ts b/src/services/index.ts deleted file mode 100644 index d7e5ad58adacbc0a0cc0cf40e7e28ad5d341be84..0000000000000000000000000000000000000000 --- a/src/services/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -export * from "./association.service"; - -export * from "./balance.service"; - -export * from "./contract.service"; - -export * from "./proposal.service"; - -export * from "./token.service"; \ No newline at end of file diff --git a/src/types/Proposal.ts b/src/types/Proposal.ts index b3fb3cbbb1db49ac24aac51079309eed44d2b2da..347c6f647c637e75ea5820c2f556ef707c96c948 100644 --- a/src/types/Proposal.ts +++ b/src/types/Proposal.ts @@ -1,7 +1,7 @@ export type Proposal = { title: string; description: string; - fct: () => void; + fct?: () => void; participationRate?: number; approveRate?: number; } \ No newline at end of file