@@ -171,6 +171,10 @@ function epg_getTokenInfoByAddress(tokenAddress) {
171171 return null ;
172172}
173173
174+ function epg_calc_with_token_markup ( value ) {
175+ return parseFloat ( value ) * ( 100 + parseFloat ( window . epg . markup_percent_token ) ) / ( 100 + parseFloat ( window . epg . markup_percent ) ) ;
176+ }
177+
174178// fill the epg-payment-info div
175179function epg_fill_token_payment_info ( token , cb ) {
176180 if ( 'undefined' === typeof cb ) {
@@ -223,7 +227,7 @@ function epg_fill_token_payment_info(token, cb) {
223227 cb . call ( null , "Failed to obtain token rate" , null ) ;
224228 return ;
225229 }
226- var tokenAmount = parseFloat ( window . epg . eth_value ) / rate ;
230+ var tokenAmount = epg_calc_with_token_markup ( window . epg . eth_value ) / rate ;
227231 // cut decimals beyond the token supported maximum
228232 var tokenAmount2 = Math . ceil ( tokenAmount * Math . pow ( 10 , decimals . toNumber ( ) ) ) ;
229233 tokenAmount = tokenAmount2 / Math . pow ( 10 , decimals . toNumber ( ) ) ;
@@ -804,52 +808,52 @@ function epg_getValuePaymentEth(cb) {
804808 epg_getCurrencyPayment ( function ( err , currencyAddress ) {
805809 if ( err ) {
806810 console . log ( err ) ;
807- cb . call ( null , err , null ) ;
811+ cb . call ( null , err , null , currencyAddress ) ;
808812 return ;
809813 }
810814 if ( currencyAddress === "0x0000000000000000000000000000000000000000" ||
811815 currencyAddress === "0x" ) {
812816 // no payment was performed
813- cb . call ( null , null , null ) ;
817+ cb . call ( null , null , null , currencyAddress ) ;
814818 return ;
815819 }
816820 epg_getValuePayment ( function ( err , value ) {
817821 if ( err ) {
818822 console . log ( err ) ;
819- cb . call ( null , err , null ) ;
823+ cb . call ( null , err , null , currencyAddress ) ;
820824 return ;
821825 }
822826 // ETH is encoded as address 0x0000000000000000000000000000000000000001
823827 if ( currencyAddress === "0x0000000000000000000000000000000000000001" ) {
824- cb . call ( null , null , value . toNumber ( ) / window . epg . web3 . toWei ( 1 , 'ether' ) ) ;
828+ cb . call ( null , null , value . toNumber ( ) / window . epg . web3 . toWei ( 1 , 'ether' ) , currencyAddress ) ;
825829 return ;
826830 }
827831 epg_get_token_decimals ( currencyAddress , function ( error , decimals ) {
828832 if ( error ) {
829833 console . log ( error ) ;
830- cb . call ( null , error , null ) ;
834+ cb . call ( null , error , null , currencyAddress ) ;
831835 return ;
832836 }
833837 if ( null === decimals ) {
834838 console . log ( "Failed to obtain ERC20 token decimals value" ) ;
835- cb . call ( null , window . epg . str_pay_token_failure , null ) ;
839+ cb . call ( null , window . epg . str_pay_token_failure , null , currencyAddress ) ;
836840 return ;
837841 }
838842 var rate = epg_getTokenRate ( currencyAddress ) ;
839843 if ( null === rate ) {
840844 console . log ( "Failed to obtain token rate" ) ;
841- cb . call ( null , window . epg . str_pay_token_failure , null ) ;
845+ cb . call ( null , window . epg . str_pay_token_failure , null , currencyAddress ) ;
842846 return ;
843847 }
844848
845849 var contract = epg_get_gateway_contract ( ) ;
846850 if ( ! contract ) {
847851 console . log ( "Failed to obtain a gateway contract" ) ;
848- cb . call ( null , "Failed to obtain a gateway contract" , null ) ;
852+ cb . call ( null , "Failed to obtain a gateway contract" , null , currencyAddress ) ;
849853 return ;
850854 }
851855 var value_eth = rate * value . toNumber ( ) / Math . pow ( 10 , decimals . toNumber ( ) ) ;
852- cb . call ( null , null , value_eth ) ;
856+ cb . call ( null , null , value_eth , currencyAddress ) ;
853857 } ) ;
854858 } ) ;
855859 } ) ;
@@ -1363,7 +1367,7 @@ function epg_initWizard(cb) {
13631367 epg_alert ( ( token === 'ETH' ) ? window . epg . str_deposit_eth_failure : window . epg . str_deposit_token_failure ) ;
13641368 return ;
13651369 }
1366- if ( null === value || epg_round ( value , 5 , "PHP_ROUND_HALF_UP" ) < epg_round ( parseFloat ( window . epg . eth_value ) , 5 , "PHP_ROUND_HALF_UP" ) ) {
1370+ if ( null === value || epg_round ( value , 5 , "PHP_ROUND_HALF_UP" ) < epg_round ( epg_calc_with_token_markup ( window . epg . eth_value ) , 5 , "PHP_ROUND_HALF_UP" ) ) {
13671371 epg_sendTransaction_impl ( function ( err , result ) {
13681372 if ( err ) {
13691373 console . log ( err ) ;
@@ -1421,7 +1425,7 @@ function epg_initWizard(cb) {
14211425 epg_alert ( ( token === 'ETH' ) ? window . epg . str_pay_eth_failure : window . epg . str_pay_token_failure ) ;
14221426 return ;
14231427 }
1424- if ( null === value || epg_round ( value , 5 , "PHP_ROUND_HALF_UP" ) < parseFloat ( window . epg . eth_value ) ) {
1428+ if ( null === value || epg_round ( value , 5 , "PHP_ROUND_HALF_UP" ) < epg_round ( epg_calc_with_token_markup ( window . epg . eth_value ) , 5 , "PHP_ROUND_HALF_UP" ) ) {
14251429 epg_sendTransaction_eth_step2_impl ( ) ;
14261430 }
14271431// jQuery('#rootwizard').bootstrapWizard('show', EPG_STEP.result);
@@ -1538,19 +1542,35 @@ jQuery(document).ready(function () {
15381542 } ) ;
15391543 }
15401544 epg_show_wait_icon ( ) ;
1541- epg_getValuePaymentEth ( function ( err , value ) {
1545+ epg_getValuePaymentEth ( function ( err , value , currencyAddress ) {
15421546 if ( err ) {
15431547 console . log ( err ) ;
15441548 epg_alert ( err ) ;
15451549 epg_hide_wait_icon ( ) ;
15461550 return ;
15471551 }
1548- if ( null === value || epg_round ( value , 5 , "PHP_ROUND_HALF_UP" ) < parseFloat ( window . epg . eth_value ) ) {
1552+ if ( null === value ) {
15491553 epg_hide_wait_icon ( ) ;
15501554 jQuery ( '#epg-payment-incomplete-message-wrapper' ) . removeClass ( 'hidden' ) ;
15511555 jQuery ( '#epg-payment-incomplete-message-wrapper' ) . removeAttr ( 'hidden' ) ;
15521556 return ;
15531557 }
1558+ // ETH is encoded as address 0x0000000000000000000000000000000000000001
1559+ if ( currencyAddress !== "0x0000000000000000000000000000000000000001" ) {
1560+ if ( epg_round ( value , 5 , "PHP_ROUND_HALF_UP" ) < epg_round ( epg_calc_with_token_markup ( window . epg . eth_value ) , 5 , "PHP_ROUND_HALF_UP" ) ) {
1561+ epg_hide_wait_icon ( ) ;
1562+ jQuery ( '#epg-payment-incomplete-message-wrapper' ) . removeClass ( 'hidden' ) ;
1563+ jQuery ( '#epg-payment-incomplete-message-wrapper' ) . removeAttr ( 'hidden' ) ;
1564+ return ;
1565+ }
1566+ } else {
1567+ if ( epg_round ( value , 5 , "PHP_ROUND_HALF_UP" ) < epg_round ( window . epg . eth_value , 5 , "PHP_ROUND_HALF_UP" ) ) {
1568+ epg_hide_wait_icon ( ) ;
1569+ jQuery ( '#epg-payment-incomplete-message-wrapper' ) . removeClass ( 'hidden' ) ;
1570+ jQuery ( '#epg-payment-incomplete-message-wrapper' ) . removeAttr ( 'hidden' ) ;
1571+ return ;
1572+ }
1573+ }
15541574 jQuery ( '#epg-payment-success-message-wrapper' ) . removeClass ( 'hidden' ) ;
15551575 jQuery ( '#epg-payment-success-message-wrapper' ) . removeAttr ( 'hidden' ) ;
15561576 jQuery ( '#epg-ether-payment' ) . addClass ( 'hidden' ) ;
0 commit comments