Skip to content

Commit

Permalink
feat: update namada to 0.18.0 (#324)
Browse files Browse the repository at this point in the history
* feat: compilation works with 0.18.0

* feat: update wasm-bindgen-cli version in CI
  • Loading branch information
mateuszjasiuk authored Jul 6, 2023
1 parent e1d9af1 commit d0a9da8
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-wallet-at-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
run: rustup target add wasm32-unknown-unknown

- name: Install wasm-bindgen-cli
run: cargo install [email protected].86
run: cargo install [email protected].87

- name: build the site
working-directory: ./apps/namada-interface
Expand Down
5 changes: 2 additions & 3 deletions apps/extension/src/background/approvals/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { v4 as uuid } from "uuid";
import BigNumber from "bignumber.js";

import { SubmitTransferMsgSchema, TransferMsgValue } from "@anoma/types";
import { amountFromMicro } from "@anoma/utils";
import { KVStore } from "@anoma/storage";

import { ExtensionRequester } from "extension";
Expand All @@ -19,7 +18,7 @@ export class ApprovalsService {
protected readonly keyRingService: KeyRingService,
protected readonly chainId: string,
protected readonly requester: ExtensionRequester
) { }
) {}

// Deserialize transfer details and prompt user
async approveTransfer(txMsg: string): Promise<void> {
Expand All @@ -34,7 +33,7 @@ export class ApprovalsService {
txMsgBuffer
);
const { source, target, token, amount: amountBN } = txDetails;
const amount = amountFromMicro(new BigNumber(amountBN.toString()));
const amount = new BigNumber(amountBN.toString());
const url = `${browser.runtime.getURL(
"approvals.html"
)}#/tx?id=${id}&source=${source}&target=${target}&token=${token}&amount=${amount}`;
Expand Down
4 changes: 2 additions & 2 deletions apps/extension/src/background/keyring/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ const handleTransferCompletedEvent: (
service: KeyRingService
) => InternalHandler<TransferCompletedEvent> = (service) => {
return async (_, msg) => {
const { msgId, success } = msg;
return await service.handleTransferCompleted(msgId, success);
const { msgId, success, payload } = msg;
return await service.handleTransferCompleted(msgId, success, payload);
};
};

Expand Down
6 changes: 5 additions & 1 deletion apps/extension/src/background/keyring/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,11 @@ export class TransferCompletedEvent extends Message<void> {
return MessageType.TransferCompletedEvent;
}

constructor(public readonly success: boolean, public readonly msgId: string) {
constructor(
public readonly success: boolean,
public readonly msgId: string,
public readonly payload?: string
) {
super();
}

Expand Down
8 changes: 7 additions & 1 deletion apps/extension/src/background/keyring/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,14 @@ export class KeyRingService {

async handleTransferCompleted(
msgId: string,
success: boolean
success: boolean,
payload?: string
): Promise<void> {
if (!success) {
//TODO: pass error message to the TransferStartedEvent and display it in the UI
console.error(payload);
}

const tabs = await syncTabs(
this.connectedTabsStore,
this.requester,
Expand Down
5 changes: 3 additions & 2 deletions apps/extension/src/background/offscreen/offscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ const SW_TTL = 20000;

const transferCompletedHandler = async (
msgId: string,
success: boolean
success: boolean,
payload?: string
): Promise<void> => {
// We are sending the message to the background script
await requester.sendMessage(
Ports.Background,
new TransferCompletedEvent(success, msgId)
new TransferCompletedEvent(success, msgId, payload)
);

// Reducing a number of tracked web workers
Expand Down
21 changes: 15 additions & 6 deletions apps/extension/src/background/web-workers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,26 @@ import {

export const init = (
data: SubmitTransferMessageData,
transferCompletedHandler: (msgId: string, success: boolean) => Promise<void>
transferCompletedHandler: (
msgId: string,
success: boolean,
payload?: string
) => Promise<void>
): void => {
const w = new Worker("submit-transfer-web-worker.anoma.js");

w.onmessage = (e: MessageEvent<Msg>) => {
if (e.data === INIT_MSG) {
const { msgName, payload } = e.data;
if (msgName === INIT_MSG) {
w.postMessage(data);
} else if (e.data === TRANSFER_SUCCESSFUL_MSG) {
transferCompletedHandler(data.msgId, true).then(() => w.terminate());
} else if (e.data === TRANSFER_FAILED_MSG) {
transferCompletedHandler(data.msgId, false).then(() => w.terminate());
} else if (msgName === TRANSFER_SUCCESSFUL_MSG) {
transferCompletedHandler(data.msgId, true, payload).then(() =>
w.terminate()
);
} else if (msgName === TRANSFER_FAILED_MSG) {
transferCompletedHandler(data.msgId, false, payload).then(() =>
w.terminate()
);
} else {
console.warn("Not supporeted msg type.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ import {
({ data }: { data: SubmitTransferMessageData }) => {
sdk
.submit_transfer(fromBase64(data.txMsg), data.password, data.xsk)
.then(() => postMessage(TRANSFER_SUCCESSFUL_MSG))
.catch(() => postMessage(TRANSFER_FAILED_MSG));
.then(() => postMessage({ msgName: TRANSFER_SUCCESSFUL_MSG }))
.catch((error) => {
postMessage({
msgName: TRANSFER_FAILED_MSG,
payload: error.message,
});
});
},
false
);

postMessage(INIT_MSG);
postMessage({ msgName: INIT_MSG });
})();
4 changes: 3 additions & 1 deletion apps/extension/src/background/web-workers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export type SubmitTransferMessageData = {
export const INIT_MSG = "init";
export const TRANSFER_SUCCESSFUL_MSG = "transfer-successful";
export const TRANSFER_FAILED_MSG = "transfer-failed";
export type Msg =
export type MsgName =
| typeof INIT_MSG
| typeof TRANSFER_FAILED_MSG
| typeof TRANSFER_SUCCESSFUL_MSG;

export type Msg = { msgName: MsgName; payload?: string };
17 changes: 7 additions & 10 deletions apps/namada-interface/src/slices/StakingAndGovernance/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createAsyncThunk } from "@reduxjs/toolkit";
import BigNumber from "bignumber.js";

import { Query } from "@anoma/shared";
import { amountToMicro } from "@anoma/utils";
import { Signer, Tokens } from "@anoma/types";
import { chains } from "@anoma/chains";
import { getIntegration } from "@anoma/hooks";
Expand All @@ -29,7 +28,7 @@ const toValidator = ([address, votingPower]: [string, string]): Validator => ({
name: address,
// TODO: voting power is multiplied by votes_per_token value defined in genesis file
// currently it is 10
votingPower: (new BigNumber(votingPower)).multipliedBy(10).toString(),
votingPower: new BigNumber(votingPower).multipliedBy(10).toString(),
homepageUrl: "http://namada.net",
commission: "TBD",
description: "TBD",
Expand All @@ -49,19 +48,17 @@ const toMyValidators = (
...arr.slice(idx + 1),
];

const stakedAmount =
(new BigNumber(stake)).plus(new BigNumber(v?.stakedAmount || 0)).toString();
const stakedAmount = new BigNumber(stake)
.plus(new BigNumber(v?.stakedAmount || 0))
.toString();

return [
...sliceFn(acc, index),
{
uuid: validator,
stakingStatus: "Bonded",
stakedAmount,
validator: toValidator([
validator,
stakedAmount,
]),
validator: toValidator([validator, stakedAmount]),
},
];
};
Expand Down Expand Up @@ -167,7 +164,7 @@ export const postNewBonding = createAsyncThunk<
await signer.submitBond({
source: change.owner,
validator: change.validatorId,
amount: amountToMicro(new BigNumber(change.amount)),
amount: new BigNumber(change.amount),
nativeToken: Tokens.NAM.address || "",
tx: {
token: Tokens.NAM.address || "",
Expand All @@ -194,7 +191,7 @@ export const postNewUnbonding = createAsyncThunk<
await signer.submitUnbond({
source: change.owner,
validator: change.validatorId,
amount: amountToMicro(new BigNumber(change.amount)),
amount: new BigNumber(change.amount),
tx: {
token: Tokens.NAM.address || "",
feeAmount: new BigNumber(0),
Expand Down
6 changes: 2 additions & 4 deletions apps/namada-interface/src/slices/transfers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import BigNumber from "bignumber.js";

import { Account, Tokens, TokenType, Signer } from "@anoma/types";
import { amountToMicro } from "@anoma/utils";
import { getIntegration } from "@anoma/hooks";

import {
Expand Down Expand Up @@ -166,7 +165,7 @@ export const submitTransferTransaction = createAsyncThunk<
source: txTransferArgs.account.address,
target: txTransferArgs.target,
token: Tokens.NAM.address || "",
amount: amountToMicro(txTransferArgs.amount),
amount: txTransferArgs.amount,
nativeToken: Tokens.NAM.address || "",
});
}
Expand Down Expand Up @@ -242,8 +241,7 @@ export const submitBridgeTransferTransaction = createAsyncThunk<
source: txBridgeTransferArgs.account.address,
target: txBridgeTransferArgs.target,
token: txBridgeTransferArgs.token,
// TODO: Check to see if amountToMicro is needed here once implemented for ETH Bridge:
amount: amountToMicro(txBridgeTransferArgs.amount),
amount: txBridgeTransferArgs.amount,
},
});

Expand Down
20 changes: 10 additions & 10 deletions packages/crypto/lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d0a9da8

Please sign in to comment.