Skip to content

Commit

Permalink
fix: add appId
Browse files Browse the repository at this point in the history
BREAKING CHANGE: App ID is required
  • Loading branch information
akasuv committed Nov 1, 2023
1 parent 9fc3b67 commit e3bc691
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/Chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ class Chain {
id: number;
sendTransactionBase: SendTransaction;
cyberAccount: CyberAccount | null = null;
appId: string;

constructor({
id,
sendTransaction,
appId,
}: {
id: number;
sendTransaction: SendTransaction;
appId: string;
}) {
this.id = id;
this.sendTransactionBase = sendTransaction;
this.appId = appId;
}

public setCyberAccount(cyberAccount: CyberAccount | null) {
Expand All @@ -24,7 +28,7 @@ class Chain {

public async sendTransaction(
transaction: Omit<WalletTransaction, "ctx">,
option?: { description?: string }
option?: { description?: string },
) {
if (!this.cyberAccount) {
return;
Expand All @@ -34,9 +38,13 @@ class Chain {
{
...transaction,
from: transaction.from || this.cyberAccount.address,
ctx: { chainId: this.id, owner: this.cyberAccount.ownerAddress },
ctx: {
chainId: this.id,
owner: this.cyberAccount.ownerAddress,
appId: this.appId,
},
},
option
option,
);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/CyberApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import Messenger from "./Messenger";
import type { AppInfo } from "./types";

class CyberApp {
public appId: string;
public name: string;
public cyberWallet: CyberWallet;
public messenger: Messenger;
public icon: string;

constructor({ name, icon }: AppInfo) {
constructor({ appId, name, icon }: AppInfo) {
this.appId = appId;
this.name = name;
this.icon = icon;
this.cyberWallet = new CyberWallet({
contextWindow: window.parent,
appInfo: { name, icon },
appInfo: { name, icon, appId },
});
this.messenger = new Messenger({
walletWindow: this.cyberWallet.contextWindow,
Expand Down
1 change: 1 addition & 0 deletions src/CyberWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class CyberWallet {
this[key as AvailableChainName] = new Chain({
id: chain.id,
sendTransaction: this.bindedSendTransaction,
appId: appInfo.appId,
});
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type WalletTransaction = {
ctx: {
chainId: number;
owner: Address;
appId: string;
};
};

Expand All @@ -54,6 +55,7 @@ export type SendTransaction = (
) => Promise<any>;

export type AppInfo = {
appId: string;
name: string;
icon: string;
};
Expand Down

0 comments on commit e3bc691

Please sign in to comment.