Skip to content

Commit

Permalink
Migrate to dpos-offline@v3 #230
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiaszCudnik committed Jun 11, 2019
1 parent fbdc8a2 commit 8b91261
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -24,7 +24,7 @@
"downshift": "^3.1.7",
"dpos-api-wrapper": "^1.3.2",
"dpos-ledger-api": "^3.0.1",
"dpos-offline": "2.0.2",
"dpos-offline": "^3.0.0",
"inobounce": "^0.1.6",
"is-mobile": "^2.0.0",
"jdenticon": "^2.1.0",
Expand Down
25 changes: 17 additions & 8 deletions src/stores/wallet.ts
Expand Up @@ -2,11 +2,12 @@ import * as assert from 'assert';
import { BaseApiResponse } from 'dpos-api-wrapper/src/types/base';
import { Account as APIAccount } from 'dpos-api-wrapper/src/types/beans';
import {
RiseTransaction as GenericRiseTransaction,
PostableRiseTransaction as GenericPostableRiseTransaction,
RiseV2Transaction as GenericRiseTransaction,
PostableRiseV2Transaction as GenericPostableRiseTransaction,
RecipientId,
Rise
} from 'dpos-offline';
import { RiseV2 } from 'dpos-offline/src/codecs/rise';
import { isMobile } from 'is-mobile';
import { get, pick } from 'lodash';
import {
Expand Down Expand Up @@ -404,8 +405,9 @@ export default class WalletStore {
assert(account, 'Account required');
const wallet2 = Rise.deriveKeypair(passphrase);

// TODO fix types in dpos-offline
return Rise.txs.transform({
kind: 'second-signature',
kind: 'second-signature-v2',
publicKey: wallet2.publicKey,
sender: account.toSenderObject()
});
Expand All @@ -422,7 +424,7 @@ export default class WalletStore {
assert(account, 'Account required');

return Rise.txs.transform({
kind: 'send',
kind: 'send-v2',
amount: amount.toString(),
recipient: recipientId as RecipientId,
sender: account.toSenderObject()
Expand All @@ -448,8 +450,9 @@ export default class WalletStore {
await this.loadVotedDelegate(account.id);
}

// TODO fix types in dpos-offline
return Rise.txs.transform({
kind: 'vote',
kind: 'vote-v2',
sender: account.toSenderObject(),
preferences: [
...(account.votedDelegate
Expand Down Expand Up @@ -496,8 +499,9 @@ export default class WalletStore {
throw new Error('Already registered as a delegate');
}

// TODO fix types in dpos-offline
return Rise.txs.transform({
kind: 'register-delegate',
kind: 'register-delegate-v2',
sender: account.toSenderObject(),
identifier: username as string & As<'delegateName'>
});
Expand All @@ -508,9 +512,14 @@ export default class WalletStore {
mnemonic: string,
passphrase: string | null = null
): PostableRiseTransaction {
const signedTx = Rise.txs.sign(unsignedTx, mnemonic);
const signedTx = RiseV2.txs.sign(unsignedTx, mnemonic);
if (passphrase) {
signedTx.signSignature = Rise.txs.calcSignature(signedTx, passphrase);
signedTx.signatures.push(
RiseV2.txs.calc2ndSignature(
unsignedTx,
RiseV2.deriveKeypair(passphrase)
)
);
}
return Rise.txs.toPostable(signedTx);
}
Expand Down

0 comments on commit 8b91261

Please sign in to comment.