Skip to content

Update the total amount #2

@ghost

Description

Feature Request

Hey. Excellent script. I would like to use it in an Online Shop for Checkout.
I kinda hacked it in a way that now I remove and regenerate the DOM object of the button each time the value changes by calling this custom function:

var extCurrency = 'EUR';

function addMetaMask() {
  if ($('#metamask-checkout').length) $('#metamask-checkout').remove();
  // create div
  $('<div/>')
    .addClass('eth-commerce-button')
    .attr('id', 'metamask-checkout')
    .appendTo("div.widget");

  // turn it into an ETHCommerce button
  var ethCommerce = new EthCommerce();
  ethCommerce.render(
  {
      targetElement: 'metamask-checkout',
      type: 'PAY',
      amount: $('span.ct-cart-total').text().replace(/\D/g,''),
      currency: extCurrency,
      address: '0x11A7Ca870700f284e4647E55DeD9040f0F86D4D4'
  }, (e)=>{
      console.log('error callback', e);
  },(tx)=>{
      console.log('success callback', tx);
  });
}

It would be cool if your class had a function to update the amount in a more elegant way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions