async function postCapsule() {
  const summary = $('#summary').val();
  const unlockDate = moment($('#unlock-date').val(), DATE_TIME_FORMAT).unix();
  
  // Generates a random encryption key and then encrypts the message
  const aesKey = CryptoJS.lib.WordArray.random(16).toString();
  const encryptedMessage = CryptoJS.AES.encrypt(
    editor.getMarkdown(), aesKey
  ).toString();

  try {
    const provider = await Web3Handler.getCurrentProvider();

    const ipfsPath = await postMessageToIPFS(encryptedMessage);
    const tx = await postCapsuleToBlockchain(summary, unlockDate, ipfsPath, aesKey, provider);

    if (tx) {
      // Go to index page and send the tx has as parameter to notify confirmation
      window.location.href = "index.html?txHash=" + tx.hash;
    }
  } catch(error) {
    console.log("error:", error);

    if(error == "NO_PROVIDER") {
      // No wallet found
      displayMessage('#alert-danger', `No wallet detected, do you want to install <a href="https://metamask.io/download.html">MetaMask</a>?`);
    } else if(error === "INVALID_NETWORK") {
      // Wallet is not connected to the expected network
      displayMessage('#alert-danger', `Please verify your wallet is connected to the <strong>${Contracts.network}</strong> network`);
    } else {
      throw error;
    }
  }
}
/**
 * Posts a capsule. The message goes to IPFS and the rest to Ethereum
 * Values taken from the dom elements
 */
Posts a capsule. The message goes to IPFS and the rest to Ethereum
Values taken from the dom elements
Posts a capsule . The message goes to IPFS and the rest to Ethereum Values taken from the dom elements
async function postCapsule() {
  const summary = $('#summary').val();
  const unlockDate = moment($('#unlock-date').val(), DATE_TIME_FORMAT).unix();
  const aesKey = CryptoJS.lib.WordArray.random(16).toString();
  const encryptedMessage = CryptoJS.AES.encrypt(
    editor.getMarkdown(), aesKey
  ).toString();
  try {
    const provider = await Web3Handler.getCurrentProvider();
    const ipfsPath = await postMessageToIPFS(encryptedMessage);
    const tx = await postCapsuleToBlockchain(summary, unlockDate, ipfsPath, aesKey, provider);
    if (tx) {
      window.location.href = "index.html?txHash=" + tx.hash;
    }
  } catch(error) {
    console.log("error:", error);
    if(error == "NO_PROVIDER") {
      displayMessage('#alert-danger', `No wallet detected, do you want to install <a href="https://metamask.io/download.html">MetaMask</a>?`);
    } else if(error === "INVALID_NETWORK") {
      displayMessage('#alert-danger', `Please verify your wallet is connected to the <strong>${Contracts.network}</strong> network`);
    } else {
      throw error;
    }
  }
}
async function postCapsule ( ) { const summary = $ ( '#summary' ) . val ( ) ; const unlockDate = moment ( $ ( '#unlock-date' ) . val ( ) , DATE_TIME_FORMAT ) . unix ( ) ; const aesKey = CryptoJS . lib . WordArray . random ( 16 ) . toString ( ) ; const encryptedMessage = CryptoJS . AES . encrypt ( editor . getMarkdown ( ) , aesKey ) . toString ( ) ; try { const provider = await Web3Handler . getCurrentProvider ( ) ; const ipfsPath = await postMessageToIPFS ( encryptedMessage ) ; const tx = await postCapsuleToBlockchain ( summary , unlockDate , ipfsPath , aesKey , provider ) ; if ( tx ) { window . location . href = "index.html?txHash=" + tx . hash ; } } catch ( error ) { console . log ( "error:" , error ) ; if ( error == "NO_PROVIDER" ) { displayMessage ( '#alert-danger' , ` ` ) ; } else if ( error === "INVALID_NETWORK" ) { displayMessage ( '#alert-danger' , ` ${ Contracts . network } ` ) ; } else { throw error ; } } }
Posts a capsule.
Posts a capsule .
// Generates a random encryption key and then encrypts the message // Go to index page and send the tx has as parameter to notify confirmation // No wallet found // Wallet is not connected to the expected network