Skip to content

Commit 0fb7263

Browse files
committed
Add an EdgeStakingSettings configuration
1 parent 368d6f4 commit 0fb7263

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-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: 25 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,13 @@ export type EdgeSpendInfo = {
223224
otherParams?: Object
224225
}
225226

227+
export type EdgeStakingSettings =
228+
| { stakingEnabled: false }
229+
| {
230+
stakingEnabled: true,
231+
delegateAddress: string
232+
}
233+
226234
// query data ----------------------------------------------------------
227235

228236
export type EdgeDataDump = {
@@ -359,6 +367,12 @@ export type EdgeCurrencyEngine = {
359367
paymentProtocolUrl: string
360368
) => Promise<EdgePaymentProtocolInfo>,
361369

370+
// Staking:
371+
+stakingSettings?: EdgeStakingSettings,
372+
changeStakingSettings?: (
373+
stakingSettings: EdgeStakingSettings
374+
) => Promise<EdgeTransaction>,
375+
362376
// Escape hatch:
363377
+otherMethods?: Object
364378
}
@@ -477,16 +491,20 @@ export type EdgeCurrencyWallet = {
477491
getEnabledTokens(): Promise<Array<string>>,
478492
addCustomToken(token: EdgeTokenInfo): Promise<mixed>,
479493

480-
// Transactions:
494+
// Transaction history:
481495
getNumTransactions(opts?: EdgeCurrencyCodeOptions): Promise<number>,
482496
getTransactions(
483497
opts?: EdgeGetTransactionsOptions
484498
): Promise<Array<EdgeTransaction>>,
499+
500+
// Addresses:
485501
getReceiveAddress(
486502
opts?: EdgeCurrencyCodeOptions
487503
): Promise<EdgeReceiveAddress>,
488504
saveReceiveAddress(receiveAddress: EdgeReceiveAddress): Promise<mixed>,
489505
lockReceiveAddress(receiveAddress: EdgeReceiveAddress): Promise<mixed>,
506+
507+
// Sending:
490508
makeSpend(spendInfo: EdgeSpendInfo): Promise<EdgeTransaction>,
491509
signTx(tx: EdgeTransaction): Promise<EdgeTransaction>,
492510
broadcastTx(tx: EdgeTransaction): Promise<EdgeTransaction>,
@@ -502,6 +520,12 @@ export type EdgeCurrencyWallet = {
502520
paymentProtocolUrl: string
503521
): Promise<EdgePaymentProtocolInfo>,
504522

523+
// Staking:
524+
+stakingSettings: EdgeStakingSettings,
525+
changeStakingSettings: (
526+
stakingSettings: EdgeStakingSettings
527+
) => Promise<EdgeTransaction>,
528+
505529
// Wallet management:
506530
resyncBlockchain(): Promise<mixed>,
507531
dumpData(): Promise<EdgeDataDump>,

0 commit comments

Comments
 (0)