useWallet hook cleanup (#1396)
* Assign everything to wallet object * Add canReceive for sake of completeness
This commit is contained in:
parent
fe0678b4cb
commit
36e9f3f16f
|
@ -45,12 +45,6 @@ export function useWallet (name) {
|
||||||
logger.info('payments disabled')
|
logger.info('payments disabled')
|
||||||
}, [name, me, logger])
|
}, [name, me, logger])
|
||||||
|
|
||||||
if (wallet) {
|
|
||||||
wallet.isConfigured = _isConfigured
|
|
||||||
wallet.enablePayments = enablePayments
|
|
||||||
wallet.disablePayments = disablePayments
|
|
||||||
}
|
|
||||||
|
|
||||||
const status = config?.enabled ? Status.Enabled : Status.Initialized
|
const status = config?.enabled ? Status.Enabled : Status.Initialized
|
||||||
const enabled = status === Status.Enabled
|
const enabled = status === Status.Enabled
|
||||||
const priority = config?.priority
|
const priority = config?.priority
|
||||||
|
@ -95,21 +89,30 @@ export function useWallet (name) {
|
||||||
|
|
||||||
if (!wallet) return null
|
if (!wallet) return null
|
||||||
|
|
||||||
return {
|
// Assign everything to wallet object so every function that is passed this wallet object in this
|
||||||
...wallet,
|
// `useWallet` hook has access to all others via the reference to it.
|
||||||
canSend: !!wallet.sendPayment,
|
// Essentially, you can now use functions like `enablePayments` _inside_ of functions that are
|
||||||
sendPayment,
|
// called by `useWallet` even before enablePayments is defined and not only in functions
|
||||||
config,
|
// that use the return value of `useWallet`.
|
||||||
save,
|
wallet.isConfigured = _isConfigured
|
||||||
delete: delete_,
|
wallet.enablePayments = enablePayments
|
||||||
deleteLogs,
|
wallet.disablePayments = disablePayments
|
||||||
setPriority,
|
wallet.canSend = !!wallet.sendPayment
|
||||||
hasConfig,
|
wallet.canReceive = !!wallet.createInvoice
|
||||||
status,
|
wallet.config = config
|
||||||
enabled,
|
wallet.save = save
|
||||||
priority,
|
wallet.delete = delete_
|
||||||
logger
|
wallet.deleteLogs = deleteLogs
|
||||||
}
|
wallet.setPriority = setPriority
|
||||||
|
wallet.hasConfig = hasConfig
|
||||||
|
wallet.status = status
|
||||||
|
wallet.enabled = enabled
|
||||||
|
wallet.priority = priority
|
||||||
|
wallet.logger = logger
|
||||||
|
|
||||||
|
// can't assign sendPayment to wallet object because it already exists
|
||||||
|
// as an imported function and thus can't be overwritten
|
||||||
|
return { ...wallet, sendPayment }
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractConfig (fields, config, client) {
|
function extractConfig (fields, config, client) {
|
||||||
|
|
Loading…
Reference in New Issue