Skip to content

Commit

Permalink
Merge pull request #5403 from WalletConnect/feat/tma
Browse files Browse the repository at this point in the history
feat: tg mini apps support
  • Loading branch information
ganchoradkov authored Oct 1, 2024
2 parents 744e71f + f0b91c5 commit d1b95c3
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 113 deletions.
185 changes: 93 additions & 92 deletions package-lock.json

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

18 changes: 17 additions & 1 deletion packages/core/src/controllers/pairing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class Pairing implements IPairing {
const topic = await this.core.crypto.setSymKey(symKey);
const expiry = calcExpiry(FIVE_MINUTES);
const relay = { protocol: RELAYER_DEFAULT_PROTOCOL };
const pairing = { topic, expiry, relay, active: false };
const pairing = { topic, expiry, relay, active: false, methods: params?.methods };
const uri = formatUri({
protocol: this.core.protocol,
version: this.core.version,
Expand All @@ -106,6 +106,7 @@ export class Pairing implements IPairing {
expiryTimestamp: expiry,
methods: params?.methods,
});
this.events.emit(PAIRING_EVENTS.create, pairing);
this.core.expirer.set(topic, expiry);
await this.pairings.set(topic, pairing);
await this.core.relayer.subscribe(topic, { transportType: params?.transportType });
Expand Down Expand Up @@ -231,6 +232,21 @@ export class Pairing implements IPairing {
}
};

public formatUriFromPairing: IPairing["formatUriFromPairing"] = (pairing) => {
this.isInitialized();
const { topic, relay, expiry, methods } = pairing;
const symKey = this.core.crypto.keychain.get(topic);
return formatUri({
protocol: this.core.protocol,
version: this.core.version,
topic,
symKey,
relay,
expiryTimestamp: expiry,
methods,
});
};

// ---------- Private Helpers ----------------------------------------------- //

private sendRequest: IPairingPrivate["sendRequest"] = async (topic, method, params) => {
Expand Down
16 changes: 16 additions & 0 deletions packages/core/test/pairing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ describe("Pairing", () => {
});
});

describe("formatUriFromPairing", () => {
it("should generate pairing uri from pairing", async () => {
let generatedUri = "";
coreA.pairing.events.once("pairing_create", (payload) => {
generatedUri = coreA.pairing.formatUriFromPairing(payload);
});
const { uri } = await coreA.pairing.create({
methods: ["eth_sendTransaction", "personal_sign"],
});
expect(generatedUri).to.be.eq(uri);
const parsedUri = parseUri(uri);
const parsedGeneratedUri = parseUri(generatedUri);
expect(parsedGeneratedUri).to.deep.equal(parsedUri);
});
});

describe("ping", () => {
it("clients can ping each other", async () => {
const { uri, topic } = await coreA.pairing.create();
Expand Down
6 changes: 3 additions & 3 deletions packages/sign-client/src/controllers/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,11 @@ export class Engine extends IEngine {
new Promise<void>(async (resolve) => {
// only attempt to handle deeplinks if they are not explicitly disabled in the session config
if (!session.sessionConfig?.disableDeepLink) {
const wcDeepLink = await getDeepLink(
const wcDeepLink = (await getDeepLink(
this.client.core.storage,
WALLETCONNECT_DEEPLINK_CHOICE,
);
handleDeeplinkRedirect({ id: clientRpcId, topic, wcDeepLink });
)) as string;
await handleDeeplinkRedirect({ id: clientRpcId, topic, wcDeepLink });
}
resolve();
}),
Expand Down
Loading

0 comments on commit d1b95c3

Please sign in to comment.