Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 21 additions & 47 deletions src/utils/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const compileProgram = async (programSource) => {

// CREATE AUCTION: ApplicationCreateTxn
export const createAuctionAction = async (senderAddress, auction) => {
console.log("Starting Auction...");


let params = await algo.algodClient.getTransactionParams().do();

Expand Down Expand Up @@ -89,7 +89,7 @@ export const createAuctionAction = async (senderAddress, auction) => {

// Sign & submit the transaction
let signedTxn = await algo.myAlgoConnect.signTransaction(txn.toByte());
console.log("Signed transaction with txID: %s", txId);

await algo.algodClient.sendRawTransaction(signedTxn.blob).do();

// Wait for transaction to be confirmed
Expand All @@ -100,25 +100,19 @@ export const createAuctionAction = async (senderAddress, auction) => {
);

// Get the completed Transaction
console.log(
"Transaction " +
txId +
" confirmed in round " +
confirmedTxn["confirmed-round"]
);


// Get created application id and notify about completion
let transactionResponse = await algo.algodClient
.pendingTransactionInformation(txId)
.do();
let appId = transactionResponse["application-index"];
console.log("Created new app-id: ", appId);

return appId;
};

// START:
export const startAuctionAction = async (senderAddress, auction) => {
console.log("Placing Bid...");


let params = await algo.algodClient.getTransactionParams().do();

Expand Down Expand Up @@ -155,7 +149,7 @@ export const startAuctionAction = async (senderAddress, auction) => {
let signedTxn = await algo.myAlgoConnect.signTransaction(
txnArray.map((txn) => txn.toByte())
);
console.log("Signed group transaction");

let tx = await algo.algodClient
.sendRawTransaction(signedTxn.map((txn) => txn.blob))
.do();
Expand All @@ -168,17 +162,12 @@ export const startAuctionAction = async (senderAddress, auction) => {
);

// Notify about completion
console.log(
"Group transaction " +
tx.txId +
" confirmed in round " +
confirmedTxn["confirmed-round"]
);

};

// BID:
export const bidAction = async (senderAddress, auction, amount) => {
console.log("Placing Bid...");


let params = await algo.algodClient.getTransactionParams().do();

Expand All @@ -190,7 +179,7 @@ export const bidAction = async (senderAddress, auction, amount) => {

amount = stringToMicroAlgos(amount);

console.log(params);


// Build required app args as Uint8Array
let bidArg = new TextEncoder().encode("bid");
Expand Down Expand Up @@ -224,7 +213,7 @@ export const bidAction = async (senderAddress, auction, amount) => {
let signedTxn = await algo.myAlgoConnect.signTransaction(
txnArray.map((txn) => txn.toByte())
);
console.log("Signed group transaction");

let tx = await algo.algodClient
.sendRawTransaction(signedTxn.map((txn) => txn.blob))
.do();
Expand All @@ -237,25 +226,20 @@ export const bidAction = async (senderAddress, auction, amount) => {
);

// Notify about completion
console.log(
"Group transaction " +
tx.txId +
" confirmed in round " +
confirmedTxn["confirmed-round"]
);

};

// END AUCTION:
export const endAuctionAction = async (senderAddress, auction) => {
console.log("Ending Auction...");


let params = await algo.algodClient.getTransactionParams().do();

params.flatFee = true;

params.fee = algosdk.ALGORAND_MIN_TX_FEE * 2;

console.log(params);


// Build required app args as Uint8Array
let endArg = new TextEncoder().encode("end");
Expand All @@ -275,7 +259,7 @@ export const endAuctionAction = async (senderAddress, auction) => {

// Sign & submit the transaction
let signedTxn = await algo.myAlgoConnect.signTransaction(txn.toByte());
console.log("Signed transaction with txID: %s", txId);

await algo.algodClient.sendRawTransaction(signedTxn.blob).do();

// Wait for transaction to be confirmed
Expand All @@ -286,17 +270,12 @@ export const endAuctionAction = async (senderAddress, auction) => {
);

// Get the completed Transaction
console.log(
"Transaction " +
txId +
" confirmed in round " +
confirmedTxn["confirmed-round"]
);

};

// DELETE AUCTION
export const deleteAuctionAction = async (senderAddress, index) => {
console.log("Deleting application");


let params = await algo.algodClient.getTransactionParams().do();
let sender = new TextEncoder().encode(senderAddress);
Expand All @@ -315,7 +294,7 @@ export const deleteAuctionAction = async (senderAddress, index) => {

// Sign & submit the transaction
let signedTxn = await algo.myAlgoConnect.signTransaction(txn.toByte());
console.log("Signed transaction with txID: %s", txId);

await algo.algodClient.sendRawTransaction(signedTxn.blob).do();

// Wait for transaction to be confirmed
Expand All @@ -326,24 +305,19 @@ export const deleteAuctionAction = async (senderAddress, index) => {
);

// Get the completed Transaction
console.log(
"Transaction " +
txId +
" confirmed in round " +
confirmedTxn["confirmed-round"]
);


// Get application id of deleted application and notify about completion
let transactionResponse = await algo.algodClient
.pendingTransactionInformation(txId)
.do();
let appId = transactionResponse["txn"]["txn"].apid;
console.log("Deleted app-id: ", appId);

};

// GET LISTINGS: Using Indexer
export const getAuctionsAction = async () => {
console.log("Fetching Listings...");

let note = new TextEncoder().encode(algo.auctionNote);
let encodedNote = Buffer.from(note).toString("base64");

Expand All @@ -366,7 +340,7 @@ export const getAuctionsAction = async () => {
}
}
}
console.log("Listings Fetched...");

return listings;
};

Expand Down