Skip to content

Commit 0f758ea

Browse files
committed
Add an EdgeStakingSettings configuration
1 parent 9aac6d3 commit 0f758ea

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
}
@@ -478,16 +492,20 @@ export type EdgeCurrencyWallet = {
478492
getEnabledTokens(): Promise<Array<string>>,
479493
addCustomToken(token: EdgeTokenInfo): Promise<mixed>,
480494

481-
// Transactions:
495+
// Transaction history:
482496
getNumTransactions(opts?: EdgeCurrencyCodeOptions): Promise<number>,
483497
getTransactions(
484498
opts?: EdgeGetTransactionsOptions
485499
): Promise<Array<EdgeTransaction>>,
500+
501+
// Addresses:
486502
getReceiveAddress(
487503
opts?: EdgeCurrencyCodeOptions
488504
): Promise<EdgeReceiveAddress>,
489505
saveReceiveAddress(receiveAddress: EdgeReceiveAddress): Promise<mixed>,
490506
lockReceiveAddress(receiveAddress: EdgeReceiveAddress): Promise<mixed>,
507+
508+
// Sending:
491509
makeSpend(spendInfo: EdgeSpendInfo): Promise<EdgeTransaction>,
492510
signTx(tx: EdgeTransaction): Promise<EdgeTransaction>,
493511
broadcastTx(tx: EdgeTransaction): Promise<EdgeTransaction>,
@@ -503,6 +521,12 @@ export type EdgeCurrencyWallet = {
503521
paymentProtocolUrl: string
504522
): Promise<EdgePaymentProtocolInfo>,
505523

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

0 commit comments

Comments
 (0)