dashed-slug.net › Forums › General discussion › Integrating Custom Wallet Adapter Methods into UI Shortcode › Reply To: Integrating Custom Wallet Adapter Methods into UI Shortcode
Hello,
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 the do_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 new DSWallets\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 deposit DSWallets\Transaction
object, and pass it to do_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 the cron()
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 the DSWallets\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