Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion blockonomics-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ function bnomics_register_scripts(){
wp_register_script( 'reconnecting-websocket', plugins_url('js/vendors/reconnecting-websocket.min.js', __FILE__), array(), get_plugin_data( __FILE__ )['Version'], array( 'strategy' => 'defer' ) );
wp_register_script( 'qrious', plugins_url('js/vendors/qrious.min.js', __FILE__), array(), get_plugin_data( __FILE__ )['Version'], array( 'strategy' => 'defer' ) );
wp_register_script( 'copytoclipboard', plugins_url('js/vendors/copytoclipboard.js', __FILE__), array(), get_plugin_data( __FILE__ )['Version'], array( 'strategy' => 'defer' ) );
wp_register_script( 'bnomics-checkout', plugins_url('js/checkout.js', __FILE__), array('reconnecting-websocket', 'qrious','copytoclipboard'), get_plugin_data( __FILE__ )['Version'], array('in_footer' => true, 'strategy' => 'defer' ) );
wp_register_script( 'ethers', plugins_url('js/vendors/ethers.js', __FILE__), array(), get_plugin_data( __FILE__ )['Version'], array( 'strategy' => 'defer' ) );
wp_register_script( 'bnomics-checkout', plugins_url('js/checkout.js', __FILE__), array('reconnecting-websocket', 'qrious','copytoclipboard', 'ethers'), get_plugin_data( __FILE__ )['Version'], array('in_footer' => true, 'strategy' => 'defer' ) );
}
}

Expand Down
14 changes: 14 additions & 0 deletions js/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ class Blockonomics {

// Hide Display Error
this._display_error_wrapper.style.display = 'none';

this.wallet();
}

async wallet() {
const connectBtn = document.getElementById('connect-wallet');

connectBtn.addEventListener('click', async () => {
const provider = new ethers.providers.Web3Provider(window.ethereum);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the injected window.ethereum will work for browser extensions.

To support web app wallets (Coinbase), hardware wallets (Ledger), and mobile wallets (Trust, Metamask mobile app), we can consider using an existing package like Web3Modal (Demo). This will support a larger number wallets and avoids us dealing with connectors for each wallet type.

const signer = provider.getSigner();

const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
const activeChainId = await ethereum.request({ method: 'eth_chainId' });
});
}

create_bindings() {
Expand Down
1 change: 1 addition & 0 deletions js/vendors/ethers.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Development scripts to compile, bundle, lint, format and minify the plugin js using wp-scripts.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "wp-scripts build js/block.js"
"build": "wp-scripts build"
},
"devDependencies": {
"@woocommerce/dependency-extraction-webpack-plugin": "^2.2.0",
Expand Down
18 changes: 16 additions & 2 deletions php/Blockonomics.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,24 @@ public function getSupportedCurrencies() {
'code' => 'bch',
'name' => 'Bitcoin Cash',
'uri' => 'bitcoincash'
)
),
'usdt' => array(
'code' => 'usdt',
'name' => 'USDT',
'uri' => 'USDT'
)
);
}
/*
* Get list of active crypto currencies
*/
public function getActiveCurrencies() {
$active_currencies = array();
$blockonomics_currencies = $this->getSupportedCurrencies();
foreach ($blockonomics_currencies as $code => $currency) {
$enabled = get_option('blockonomics_'.$code);
if ($code === 'usdt') {
$enabled = true;
}
if($enabled || ($code === 'btc' && $enabled === false )){
$active_currencies[$code] = $currency;
}
Expand Down Expand Up @@ -593,6 +600,7 @@ public function get_checkout_context($order, $crypto){
if (array_key_exists('error', $order)) {
$error_context = $this->get_error_context('generic');
} else {

$context['order'] = $order;

if ($order['payment_status'] == 1 || ($order['payment_status'] == 2 && !$this->is_order_underpaid($order)) ) {
Expand All @@ -602,6 +610,12 @@ public function get_checkout_context($order, $crypto){
} else if (($order['payment_status'] == 2 && $this->is_order_underpaid($order)) && !$this->is_partial_payments_active() ) {
$error_context = $this->get_error_context('underpaid');
} else {

if ($crypto === 'usdt') {

}


// Display Checkout Page
$context['order_amount'] = $this->fix_displaying_small_values($order['expected_satoshi']);
// Payment URI is sent as part of context to provide initial Payment URI, this can be calculated using javascript
Expand Down
6 changes: 6 additions & 0 deletions templates/blockonomics_checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
</tr>
</table>

<table>
<tr>
<td><button id="connect-wallet">Connect wallet</button></td>
</tr>
</table>

<table class="blockonomics_checkout_table_outer">
<tr class="bnomics-checkout-row">
<td>
Expand Down