Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Fix bug on default chain selected
Browse files Browse the repository at this point in the history
  • Loading branch information
atmoner committed Jan 19, 2023
1 parent 019dbc9 commit 9c7b4fe
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions controllers/front/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public function postProcess()
$checkError = true;
}

if($cart->id && $checkError === false) {
if($cart->id && $checkError === false && $unserializeChains !== false) {
$this->context->smarty->assign('totalAmount', round(Configuration::get('BITCANNA_TOTAL_'.$cart->id), 4));
$this->context->smarty->assign('memo', $returnTrans[0]["memo"]);
$this->context->smarty->assign('viewDenom', $returnTrans[0]["viewDenom"]);
Expand All @@ -405,7 +405,7 @@ public function postProcess()
$this->context->smarty->assign('unserializeChains', $unserializeChains);
$this->context->smarty->assign('mainDomain', Context::getContext()->shop->getBaseURL(true));
$this->setTemplate('module:cosmospay/views/templates/front/payment_return.tpl');
} elseif ($checkError === true) {
} elseif ($checkError === true || $unserializeChains === false) {
$this->setTemplate('module:cosmospay/views/templates/front/bad_config.tpl');
} else {
$this->context->smarty->assign('mainDomain', Context::getContext()->shop->getBaseURL(true));
Expand Down
10 changes: 6 additions & 4 deletions cosmospay.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct()
{
$this->name = 'cosmospay';
$this->tab = 'payments_gateways';
$this->version = '1.0.14';
$this->version = '1.0.15';
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
$this->author = 'Bitcanna';
$this->controllers = array('validation');
Expand Down Expand Up @@ -129,14 +129,16 @@ public function processConfiguration()

Configuration::updateValue('CONF_COSMOS_TITLE', $moduleTitle);
Configuration::updateValue('CONF_COSMOS_DESC', $moduleDesc);

if (!$checkChains) {
Configuration::updateValue('CONF_COSMOS_CHAINS', serialize($checkChains));
Configuration::updateValue('CONF_COSMOS_CHAINS_ADDR', serialize($input));

/*if (!$checkChains) {
Configuration::updateValue('CONF_COSMOS_CHAINS', '');
Configuration::updateValue('CONF_COSMOS_CHAINS_ADDR', '');
} else {
Configuration::updateValue('CONF_COSMOS_CHAINS', serialize($checkChains));
Configuration::updateValue('CONF_COSMOS_CHAINS_ADDR', serialize($input));
}
}*/


$this->context->smarty->assign('confirmation', 'ok');
Expand Down
6 changes: 3 additions & 3 deletions js/mainscript.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function startChecking( order_id, mainDomain, memo, isBlocked, nonceSelectChain, nonceDeleteOrder, nonceSwitchMethod ) {
function startChecking( order_id, mainDomain, memo, isBlocked, nonceSelectChain, nonceDeleteOrder, nonceSwitchMethod, setDefault ) {

$( '#chainIcon' ).hide()
$( '#chainIcon2' ).hide()
Expand Down Expand Up @@ -27,8 +27,8 @@ function startChecking( order_id, mainDomain, memo, isBlocked, nonceSelectChain,
})
} else {
$('#mainTransaction').show();
$.post( mainDomain+"/index.php?fc=module&module=cosmospay&controller=validation", { switch: 'BitCanna', order_id: order_id, nonce: nonceSelectChain }, async function( result ) {
let foundChain = await exportCosmosConfig.initConfig.find( element => element.name === 'BitCanna' )
$.post( mainDomain+"/index.php?fc=module&module=cosmospay&controller=validation", { switch: setDefault, order_id: order_id, nonce: nonceSelectChain }, async function( result ) {
let foundChain = await exportCosmosConfig.initConfig.find( element => element.name === setDefault )

if(result.status === "canceled") {
window.location.replace(mainDomain + "index.php?fc=module&module=cosmospay&controller=validation&cancel")
Expand Down
6 changes: 5 additions & 1 deletion views/templates/front/payment_return.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{$orderSymbol}{$orderValue}
</div>
</div>

<div class="cosmos-content">
<p>Select your cryptocurrency:</p>
<div class="box">
Expand Down Expand Up @@ -167,14 +168,17 @@ console.log(exportCosmosConfig)
var nonceSelectChain = ""
var nonceDeleteOrder = ""
var nonceSwitchMethod = ""
var nonceSwitchMethod = ""
var setDefault = "{$unserializeChains[0]}"
startChecking(
order_id,
mainDomain,
memo,
isBlocked,
nonceSelectChain,
nonceDeleteOrder,
nonceSwitchMethod
nonceSwitchMethod,
setDefault
);
}
</script>
Expand Down
26 changes: 12 additions & 14 deletions views/templates/hook/getContent.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

<br />
<legend>Your receiving addresses</legend>
{foreach from=$configCosmos key=k item=v}
{foreach from=$configCosmos key=k item=v}
{if $inputActive}
{foreach from=$inputActive key=dbk item=dbv}
{if $dbk eq $v->name}
Expand Down Expand Up @@ -136,17 +136,15 @@
import bech32 from "bech32";
$(document).ready(function() {
$( 'input[name="checkChains[]"]' ).click(function () {
if ($(this).is(':checked')) {
$("#addInput").append(
'<input type="hidden" name="input['+$(this).val()+']">'
);
//$("#"+$(this).val()).show();
} else {
$("#"+$(this).val()).remove();
// $("#"+$(this).val()).hide();
}
});
// $( 'input[name="checkChains[]"]' ).click(function () {
// if ($(this).is(':checked')) {
// $("#addInput").append(
// '<input type="hidden" name="input['+$(this).val()+']">'
// );
// } else {
// $("#"+$(this).val()).remove();
// }
// });
$.getJSON( "https://store-api.bitcanna.io", async function( result ) {
Expand All @@ -157,7 +155,7 @@ $(document).ready(function() {
console.log($(this).val())
try {
let bech32Decode = bech32.decode($(this).val())
console.log(bech32Decode)
//console.log(bech32Decode)
if (bech32Decode.prefix === element.coinLookup.addressPrefix) {
$("#goodAddr_"+element.name).show();
$("#badAddr_"+element.name).hide();
Expand All @@ -171,7 +169,7 @@ $(document).ready(function() {
}
} catch (error) {
console.error(error);
// console.error(error);
$("#goodAddr_"+element.name).hide();
$("#badAddrPrefix_"+element.name).hide();
$("#badAddr_"+element.name).show();
Expand Down

0 comments on commit 9c7b4fe

Please sign in to comment.