Skip to content

Commit

Permalink
feat: compilation works with 0.18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszjasiuk committed Jul 6, 2023
1 parent 6fe3564 commit e792a9c
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 102 deletions.
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 };
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 e792a9c

Please sign in to comment.