Skip to content

Commit 56706d3

Browse files
committed
Add an EdgeStakingSettings configuration
1 parent 368d6f4 commit 56706d3

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/core/currency/wallet/currency-wallet-api.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { add, div, lte, mul, sub } from 'biggystring'
44
import { type Disklet } from 'disklet'
5-
import { bridgifyObject, onMethod, watchMethod } from 'yaob'
5+
import { bridgifyObject, onMethod, update, watchMethod } from 'yaob'
66

77
import { CurrencyWalletSync } from '../../../client-side.js'
88
import {
@@ -20,6 +20,7 @@ import {
2020
type EdgePaymentProtocolInfo,
2121
type EdgeReceiveAddress,
2222
type EdgeSpendInfo,
23+
type EdgeStakingSettings,
2324
type EdgeTokenInfo,
2425
type EdgeTransaction,
2526
type EdgeWalletInfo
@@ -459,6 +460,23 @@ export function makeCurrencyWalletApi (
459460
return getMax('0', add(balance, '1'))
460461
},
461462

463+
get stakingSettings (): EdgeStakingSettings {
464+
return engine.stakingSettings != null
465+
? engine.stakingSettings
466+
: { stakingEnabled: false }
467+
},
468+
469+
async changeStakingSettings (
470+
stakingSettings: EdgeStakingSettings
471+
): Promise<EdgeTransaction> {
472+
if (engine.changeStakingSettings == null) {
473+
throw new Error('This currency does not support staking')
474+
}
475+
const tx = await engine.changeStakingSettings(stakingSettings)
476+
update(out) // Check for changes to this.stakingSettings
477+
return tx
478+
},
479+
462480
async parseUri (uri: string, currencyCode?: string): Promise<EdgeParsedUri> {
463481
const tools = await getCurrencyTools(ai, walletInfo.type)
464482
return tools.parseUri(

src/types/types.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export type EdgeCurrencyInfo = {
137137
pluginName: string,
138138
denominations: Array<EdgeDenomination>,
139139
requiredConfirmations?: number,
140+
supportsStaking?: boolean,
140141
walletType: string,
141142

142143
// Configuration options:
@@ -223,6 +224,11 @@ export type EdgeSpendInfo = {
223224
otherParams?: Object
224225
}
225226

227+
export type EdgeStakingSettings = {
228+
stakingEnabled: boolean,
229+
delegateAddress?: string
230+
}
231+
226232
// query data ----------------------------------------------------------
227233

228234
export type EdgeDataDump = {
@@ -359,6 +365,12 @@ export type EdgeCurrencyEngine = {
359365
paymentProtocolUrl: string
360366
) => Promise<EdgePaymentProtocolInfo>,
361367

368+
// Staking:
369+
+stakingSettings?: EdgeStakingSettings,
370+
changeStakingSettings?: (
371+
stakingSettings: EdgeStakingSettings
372+
) => Promise<EdgeTransaction>,
373+
362374
// Escape hatch:
363375
+otherMethods?: Object
364376
}
@@ -477,16 +489,20 @@ export type EdgeCurrencyWallet = {
477489
getEnabledTokens(): Promise<Array<string>>,
478490
addCustomToken(token: EdgeTokenInfo): Promise<mixed>,
479491

480-
// Transactions:
492+
// Transaction history:
481493
getNumTransactions(opts?: EdgeCurrencyCodeOptions): Promise<number>,
482494
getTransactions(
483495
opts?: EdgeGetTransactionsOptions
484496
): Promise<Array<EdgeTransaction>>,
497+
498+
// Addresses:
485499
getReceiveAddress(
486500
opts?: EdgeCurrencyCodeOptions
487501
): Promise<EdgeReceiveAddress>,
488502
saveReceiveAddress(receiveAddress: EdgeReceiveAddress): Promise<mixed>,
489503
lockReceiveAddress(receiveAddress: EdgeReceiveAddress): Promise<mixed>,
504+
505+
// Sending:
490506
makeSpend(spendInfo: EdgeSpendInfo): Promise<EdgeTransaction>,
491507
signTx(tx: EdgeTransaction): Promise<EdgeTransaction>,
492508
broadcastTx(tx: EdgeTransaction): Promise<EdgeTransaction>,
@@ -502,6 +518,12 @@ export type EdgeCurrencyWallet = {
502518
paymentProtocolUrl: string
503519
): Promise<EdgePaymentProtocolInfo>,
504520

521+
// Staking:
522+
+stakingSettings: EdgeStakingSettings,
523+
changeStakingSettings: (
524+
stakingSettings: EdgeStakingSettings
525+
) => Promise<EdgeTransaction>,
526+
505527
// Wallet management:
506528
resyncBlockchain(): Promise<mixed>,
507529
dumpData(): Promise<EdgeDataDump>,

0 commit comments

Comments
 (0)