dashed-slug.net › Forums › General discussion › Integrating Custom Wallet Adapter Methods into UI Shortcode
Tagged: wallet custom-wallet-adapter
- This topic has 2 replies, 2 voices, and was last updated 5 months, 3 weeks ago by ailtonbauque.
-
AuthorPosts
-
June 21, 2024 at 2:24 pm #13708ailtonbauqueParticipant
Hello,
I am currently in the process of developing a custom wallet adapter for bitcoin-altcoin-wallets-wordpress-plugin, specifically tailored to interface with a mobile wallet API for fiat currencies.
I have successfully implemented the adapter along with its required methods. However, I am now seeking guidance on how to integrate these methods into the plugin’s UI shortcode functionality. From my observation, the plugin currently utilizes a REST API approach using JavaScript, Knockout.js.
How can I call the methods from my custom wallet adapter within the UI shortcode? Specifically, implementing functionalities such as depositing funds via the shortcode interface.
Any assistance or documentation you can provide regarding integrating this into the plugin’s frontend UI would be greatly appreciated.
Thanks for your attention.
Best regards,June 22, 2024 at 5:43 am #13709alexgKeymasterHello,
It sounds like you are doing something wrong.
If you have implemented the wallet adapter correctly, then you shouldn’t have to do anything else. You should be able to perform deposits and withdrawals via the plugin’s built-in UIs (
[wallets_deposit]
and[wallets_withdraw]
). The WP-REST API is useful only if you want to add new UIs, such as functionality that doesn’t already exist in the plugin.Available materials
The documentation and sample code for implementing a wallet adapter is here:
You can also study the Monero Wallet adapter which is available for free download, or the build-in Bitcoin core adapter, which works for any forks of Bitcoin core with the same RPC API (Litecoin, Dogecoin, Bitcoin Cash, etc).
I wouldrecommend that you start by following the instructions to setup the adapter and its settings. You may want to start from this template code: https://github.com/dashed-slug/my-wallet-adapter
Withdrawals
Implementing withdrawals is easy: just fill in the implementation for
do_withdrawals()
. Process the withdrawals and change their state on the withdrawal transactions afterwards. You can also set any TXID or timestamp or other data if you like. They will be saved by the plugin to the DB after thedo_withdrawals()
call.Here’s how the withdrawals are implemented for Bitcoin core:
Deposits
Implementing deposits is a two step process:
1. Implement the
get_new_address()
method which should return a newDSWallets\Address
for the wallet. This is what the shortcode[wallets_deposit]
displays.2. Implement deposit detection via polling: You would typically do this in the adapter’s
cron()
method which is called periodically. Once your cron code detects a new deposit, create a depositDSWallets\Transaction
object, and pass it todo_deposit()
from the abstract superclass:https://github.com/dashed-slug/wallets/blob/6.3.1/adapters/abstract-wallet-adapter.php#L326
The adapter’s
cron()
method gets called on cron runs, but not on every one. The plugin rotates between all active wallet adapters, and calls thecron()
method of only one adapter each time. To see what cron tasks are run, you can enable verbose logging from the plugin’s settings.The withdrawals are executed by the
DSWallets\Withdrawals_Task
cron.The
cron()
method is executed by theDSWallets\Adapters_Task
cron.If you end up publishing your adapter, let me know if you want me to add a link from this website to the adapter.
Hope this helps. Please do contact me with any questions you may have about the plugin.
with regards
June 27, 2024 at 4:16 am #13712ailtonbauqueParticipantThanks, it helped.
Definitely I was it approaching wrong. Went throughout the docs with your explanation and it’s starting to work.Yes, I will let you know when I publish it or have other issues.
Thank you for your attention.
Best regards, -
AuthorPosts
- You must be logged in to reply to this topic.