Skip to content

Commit

Permalink
Merge branch 'feat/wallet-connect-v2' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
yasincaliskan committed May 1, 2024
2 parents ea49ffd + c7a40ae commit 388fdc5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 213 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/beta-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18.x
registry-url: https://registry.npmjs.org

- name: Build app
Expand Down
55 changes: 6 additions & 49 deletions src/PeraWalletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {getMetaInfo, waitForTabOpening} from "./util/dom/domUtils";
import {generateEmbeddedWalletURL} from "./util/peraWalletUtils";

interface PeraWalletConnectOptions {
projectId: string;
projectId?: string;
deep_link?: string;
app_meta?: AppMeta;
network?: PeraWalletNetwork;
Expand All @@ -54,10 +54,10 @@ interface PeraWalletConnectOptions {

class PeraWalletConnect {
client: Client | null;
projectId: string;
shouldShowSignTxnToast: boolean;
network = getNetworkFromStorage();
session: SessionTypes.Struct | null;
projectId?: string;
chainId?: number;
compactMode?: boolean;

Expand Down Expand Up @@ -85,7 +85,9 @@ class PeraWalletConnect {
options?.network || "mainnet"
);

this.projectId = options.projectId;
if (options.projectId) {
this.projectId = options.projectId;
}

this.shouldShowSignTxnToast =
typeof options?.shouldShowSignTxnToast === "undefined"
Expand Down Expand Up @@ -633,8 +635,6 @@ class PeraWalletConnect {
chainId: walletDetails.chainId
});

console.log(response);

// We send the full txn group to the mobile wallet.
// Therefore, we first filter out txns that were not signed by the wallet.
// These are received as `null`.
Expand Down Expand Up @@ -739,32 +739,6 @@ class PeraWalletConnect {
}
}

// Disable arbitrary data signing for Web Wallet
// private signDataWithWeb({
// data,
// signer,
// chainId,
// webWalletURL
// }: {
// data: PeraWalletArbitraryData[];
// signer: string;
// chainId: AlgorandChainIDs;
// webWalletURL: string;
// }): Promise<Uint8Array[]> {
// return new Promise<Uint8Array[]>((resolve, reject) =>
// runWebSignTransactionFlow({
// method: "SIGN_DATA",
// signTxnRequestParams: data,
// signer,
// chainId,
// webWalletURL,
// // isCompactMode: this.compactMode,
// resolve,
// reject
// })
// );
// }

async signTransaction(
txGroups: SignerTransaction[][],
signerAddress?: string
Expand Down Expand Up @@ -801,7 +775,7 @@ class PeraWalletConnect {
// ================================================= //
}

signData(data: Uint8Array, message: string, signer: string): Promise<Uint8Array[]> {
signData(data: Uint8Array, signer: string, message: string,): Promise<Uint8Array[]> {
// eslint-disable-next-line no-magic-numbers
const chainId = (this.chainId || 4160) as AlgorandChainIDs;

Expand All @@ -819,23 +793,6 @@ class PeraWalletConnect {
}
}

// Pera Wallet Web flow
// if (this.platform === "web") {
// const {webWalletURL} = await getPeraConnectConfig();

// return this.signDataWithWeb({
// data,
// signer,
// chainId,
// webWalletURL
// });
// }

// const b64encodedData = data.map((item) => ({
// ...item,
// data: Buffer.from(item).toString('base64')
// }));

// Pera Mobile Wallet flow
return this.signDataWithMobile({data: Buffer.from(data).toString('base64'), message, signer, chainId});
}
Expand Down
65 changes: 0 additions & 65 deletions src/util/connect/connectFlow.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,29 @@
import {
// PERA_WALLET_IFRAME_ID,
PERA_WALLET_CONNECT_MODAL_ID,
removeModalWrapperFromDOM,
// getHeaderCloseButton
} from "../../modal/peraWalletConnectModalUtils";
import PeraWalletConnectError from "../PeraWalletConnectError";
// import {peraWalletFlowType} from "../device/deviceUtils";
import {
// WAIT_FOR_TAB_MAX_TRY_COUNT,
// WAIT_FOR_TAB_TRY_INTERVAL,
getMetaInfo,
waitForTabOpening
} from "../dom/domUtils";
import appTellerManager, {PeraTeller} from "../network/teller/appTellerManager";
import {getPeraWebWalletURL} from "../peraWalletConstants";
// import {generateEmbeddedWalletURL} from "../peraWalletUtils";
import {RunWebConnectFlowTypes} from "./connectFlowModels";
import {
// embeddedConnectFlowTellerReducer,
newTabConnectFlowTellerReducer
} from "./connectFlowReducers";

function runWebConnectFlow({
webWalletURL,
chainId,
// isCompactMode,
resolve,
reject
}: RunWebConnectFlowTypes) {
const webWalletURLs = getPeraWebWalletURL(webWalletURL);

// if (peraWalletFlowType() === "EMBEDDED") {
// return runEmbeddedWebConnectFlow;
// }

return runNewTabWebConnectFlow;

// =========== Embedded Connect Flow ===========
// function runEmbeddedWebConnectFlow(peraWalletIframeWrapper: Element) {
// const peraWalletIframe = document.createElement("iframe");

// peraWalletIframe.setAttribute("id", PERA_WALLET_IFRAME_ID);
// peraWalletIframe.setAttribute(
// "src",
// generateEmbeddedWalletURL(webWalletURLs.CONNECT, isCompactMode)
// );

// peraWalletIframeWrapper.appendChild(peraWalletIframe);

// if (peraWalletIframe.contentWindow) {
// let count = 0;

// const isIframeInitializedChecker = setInterval(() => {
// count += 1;

// if (count === WAIT_FOR_TAB_MAX_TRY_COUNT) {
// clearInterval(isIframeInitializedChecker);

// return;
// }

// appTellerManager.sendMessage({
// message: {
// type: "IFRAME_INITIALIZED"
// },

// origin: webWalletURLs.CONNECT,
// targetWindow: peraWalletIframe.contentWindow!
// });

// getHeaderCloseButton("connect")?.addEventListener("click", () => {
// clearInterval(isIframeInitializedChecker);
// });
// }, WAIT_FOR_TAB_TRY_INTERVAL);

// appTellerManager.setupListener({
// onReceiveMessage: (event: MessageEvent<TellerMessage<PeraTeller>>) =>
// embeddedConnectFlowTellerReducer({
// event,
// peraWalletIframe,
// chainId,
// isIframeInitializedChecker,
// webWalletURLs,
// resolve,
// reject
// })
// });
// }
// }

// =========== New Tab Connect Flow ===========
async function runNewTabWebConnectFlow() {
try {
Expand Down
99 changes: 1 addition & 98 deletions src/util/sign/signTransactionFlow.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
// import {
// openPeraWalletSignTxnModal,
// PERA_WALLET_IFRAME_ID,
// setupPeraWalletConnectModalCloseListener,
// PERA_WALLET_SIGN_TXN_MODAL_ID,
// getHeaderCloseButton
// } from "../../modal/peraWalletConnectModalUtils";
import PeraWalletConnectError from "../PeraWalletConnectError";
// import {peraWalletFlowType} from "../device/deviceUtils";
import {
// WAIT_FOR_TAB_MAX_TRY_COUNT,
// WAIT_FOR_TAB_TRY_INTERVAL,
waitForTabOpening
} from "../dom/domUtils";
import {PeraWalletArbitraryData, PeraWalletTransaction} from "../model/peraWalletModels";
import appTellerManager, {PeraTeller} from "../network/teller/appTellerManager";
import {getPeraWebWalletURL} from "../peraWalletConstants";
// import {generateEmbeddedWalletURL} from "../peraWalletUtils";
import {RunSignTransactionFlowParams} from "./signTransactionFlowModels";
import {
// embeddedSignTransactionFlowTellerReducer,
newTabSignTransactionFlowTellerReducer
} from "./signTransactionFlowReducers";

Expand All @@ -35,92 +23,7 @@ function runWebSignTransactionFlow({
const webWalletURLs = getPeraWebWalletURL(webWalletURL);

runNewTabSignFlow();
// switch (peraWalletFlowType()) {
// case "EMBEDDED":
// runEmbeddedSignTransactionFlow();
// break;

// case "NEW_TAB":
// break;

// default:
// break;
// }

// =========== Embedded Sign Flow ===========
// async function runEmbeddedSignTransactionFlow() {
// const peraWalletSignTxnModalIFrameWrapper = await openPeraWalletSignTxnModal({
// isCompactMode
// });

// const peraWalletIframe = document.createElement("iframe");
// const peraWalletIframeSrc = generateEmbeddedWalletURL(
// webWalletURLs.TRANSACTION_SIGN,
// isCompactMode
// );
// const peraWalletIframeAllow = `hid ${peraWalletIframeSrc}; bluetooth ${peraWalletIframeSrc}`;

// peraWalletIframe.setAttribute("id", PERA_WALLET_IFRAME_ID);
// peraWalletIframe.setAttribute("src", peraWalletIframeSrc);
// peraWalletIframe.setAttribute("allow", peraWalletIframeAllow);

// peraWalletSignTxnModalIFrameWrapper?.appendChild(peraWalletIframe);

// setupPeraWalletConnectModalCloseListener(PERA_WALLET_SIGN_TXN_MODAL_ID, () =>
// reject(
// new PeraWalletConnectError(
// {
// type: `${method}_CANCELLED`
// },
// "Transaction signing is cancelled by user."
// )
// )
// );

// if (peraWalletIframe.contentWindow) {
// let count = 0;

// const isIframeInitializedChecker = setInterval(() => {
// count += 1;

// if (count === WAIT_FOR_TAB_MAX_TRY_COUNT) {
// clearInterval(isIframeInitializedChecker);

// return;
// }

// appTellerManager.sendMessage({
// message: {
// type: "IFRAME_INITIALIZED"
// },

// origin: webWalletURLs.TRANSACTION_SIGN,
// targetWindow: peraWalletIframe.contentWindow!
// });

// getHeaderCloseButton("sign-txn")?.addEventListener("click", () => {
// clearInterval(isIframeInitializedChecker);
// });
// }, WAIT_FOR_TAB_TRY_INTERVAL);

// appTellerManager.setupListener({
// onReceiveMessage: (event: MessageEvent<TellerMessage<PeraTeller>>) =>
// embeddedSignTransactionFlowTellerReducer({
// event,
// signTxnRequestParams,
// peraWalletIframe,
// isIframeInitializedChecker,
// webWalletURLs,
// method,
// signer,
// chainId,
// resolve,
// reject
// })
// });
// }
// }


// =========== New Tab Sign Flow ===========
async function runNewTabSignFlow() {
try {
Expand Down

0 comments on commit 388fdc5

Please sign in to comment.