Skip to content

Commit

Permalink
Properly hook up schema for BondMsg
Browse files Browse the repository at this point in the history
  • Loading branch information
jurevans committed Jul 11, 2023
1 parent 187fed5 commit ab4d5e1
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
10 changes: 2 additions & 8 deletions apps/extension/src/Approvals/ApproveBond/ConfirmLedgerBond.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Button, ButtonVariant } from "@anoma/components";
import { Ledger } from "background/ledger";
import {
GetBondBytesMsg,
SubmitSignedTransferMsg,
SubmitSignedBondMsg,
} from "background/ledger/messages";
import { Ports } from "router";
import { closeCurrentTab } from "utils";
Expand Down Expand Up @@ -56,13 +56,7 @@ export const ConfirmLedgerBond: React.FC<Props> = ({ msgId }) => {
// Submit signatures for tx
await requester.sendMessage(
Ports.Background,
// TODO: new SubmitSignedBondMsg(msgId)
new SubmitSignedTransferMsg(
msgId,
toBase64(bytes),
signatures,
publicKey
)
new SubmitSignedBondMsg(msgId, toBase64(bytes), signatures, publicKey)
);
setStatus(Status.Completed);
} catch (e) {
Expand Down
3 changes: 1 addition & 2 deletions apps/extension/src/background/approvals/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const getHandler: (service: ApprovalsService) => Handler = (service) => {
);
case ApproveBondMsg:
return handleApproveBondMsg(service)(env, msg as ApproveBondMsg);

case RejectTxMsg:
return handleRejectTxMsg(service)(env, msg as RejectTxMsg);
case SubmitApprovedTransferMsg:
Expand Down Expand Up @@ -63,7 +62,7 @@ const handleSubmitApprovedTransferMsg: (

const handleApproveBondMsg: (
service: ApprovalsService
) => InternalHandler<ApproveTransferMsg> = (service) => {
) => InternalHandler<ApproveBondMsg> = (service) => {
return async (_, { txMsg, accountType }) => {
return await service.approveBond(txMsg, accountType);
};
Expand Down
9 changes: 5 additions & 4 deletions apps/extension/src/background/approvals/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import BigNumber from "bignumber.js";

import {
AccountType,
BondMsgValue,
SubmitBondMsgSchema,
SubmitTransferMsgSchema,
TransferMsgValue,
Expand Down Expand Up @@ -53,15 +54,15 @@ export class ApprovalsService {
// Decode tx details and launch approval screen
const txDetails = deserialize(
SubmitBondMsgSchema,
TransferMsgValue,
BondMsgValue,
txMsgBuffer
);
const { source, token, amount: amountBN } = txDetails;
const amount = new BigNumber(amountBN.toString());

const { source, native_token, amount: amountBN } = txDetails;
const amount = new BigNumber(amountBN.toString());
const url = `${browser.runtime.getURL(
"approvals.html"
)}#/approve-bond?type=${type}&id=${id}&source=${source}&token=${token}&amount=${amount}`;
)}#/approve-bond?type=${type}&id=${id}&source=${source}&token=${native_token}&amount=${amount}`;

this._launchApprovalWindow(url);
}
Expand Down
3 changes: 2 additions & 1 deletion apps/extension/src/background/ledger/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ResponseSign } from "@zondax/ledger-namada";
import {
AccountType,
Bip44Path,
BondMsgValue,
SubmitBondMsgSchema,
SubmitTransferMsgSchema,
TransferMsgValue,
Expand Down Expand Up @@ -117,7 +118,7 @@ export class LedgerService {
// Deserialize txMsg to retrieve source
const { source } = deserialize(
SubmitBondMsgSchema,
TransferMsgValue,
BondMsgValue,
Buffer.from(fromBase64(txMsg))
);

Expand Down
14 changes: 8 additions & 6 deletions apps/extension/src/provider/Signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Anoma,
AccountMsgValue,
AccountMsgSchema,
BondMsgValue,
SubmitIbcTransferMsgSchema,
IbcTransferMsgValue,
IbcTransferProps,
Expand All @@ -14,7 +15,6 @@ import {
TransferProps,
AccountType,
SubmitBondProps,
SubmitBondMsgValue,
SubmitBondMsgSchema,
SubmitTransferMsgSchema,
SubmitUnbondMsgValue,
Expand Down Expand Up @@ -47,12 +47,14 @@ export class Signer implements ISigner {
args: SubmitBondProps,
type: AccountType
): Promise<void> {
const msgValue = new SubmitBondMsgValue(args);
const bondValue = new BondMsgValue(args);
const bondMsg = new Message<BondMsgValue>();
const serializedBond = bondMsg.encode(SubmitBondMsgSchema, bondValue);

const msg = new Message<SubmitBondMsgValue>();
const encoded = msg.encode(SubmitBondMsgSchema, msgValue);

return await this._anoma.submitBond({ txMsg: toBase64(encoded), type });
return await this._anoma.submitBond({
txMsg: toBase64(serializedBond),
type,
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export const NewBondingPosition = (props: Props): JSX.Element => {
owner: currentAddress,
validatorId: currentBondingPositions[0].validatorId,
};
console.log({ changeInStakingPosition });
confirmBonding(changeInStakingPosition);
}}
disabled={isEntryIncorrectOrEmpty}
Expand Down
15 changes: 9 additions & 6 deletions packages/types/src/tx/schema/bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ import { SubmitBondProps } from "../types";
import { TxMsgSchema, TxMsgValue } from "./tx";
import { SchemaObject } from "@anoma/utils";

export class SubmitBondMsgValue {
export class BondMsgValue {
source: string;
validator: string;
amount: BN;
native_token: string;
tx: TxMsgValue;

constructor(properties: SubmitBondProps | SchemaObject<typeof BondMsgSchema>) {
constructor(
properties: SubmitBondProps | SchemaObject<typeof BondMsgSchema>
) {
this.source = properties.source;
this.validator = properties.validator;
this.amount = new BN(properties.amount.toString());
this.native_token = "nativeToken" in properties ?
properties.nativeToken :
properties.native_token;
this.native_token =
"nativeToken" in properties
? properties.nativeToken
: properties.native_token;
this.tx = new TxMsgValue(properties.tx);
}
}

export const BondMsgSchema = [
SubmitBondMsgValue,
BondMsgValue,
{
kind: "struct",
fields: [
Expand Down

0 comments on commit ab4d5e1

Please sign in to comment.