Skip to content

Commit

Permalink
Fix/walletconnect android not opening when signing (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
codingki authored Dec 3, 2024
2 parents 6209154 + c6013e3 commit 0d78a5f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/graz/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "graz",
"description": "React hooks for Cosmos",
"version": "0.1.29",
"version": "0.1.30",
"author": "Griko Nibras <griko@strange.love>",
"repository": "https://github.com/graz-sh/graz.git",
"homepage": "https://github.com/graz-sh/graz",
Expand Down
10 changes: 7 additions & 3 deletions packages/graz/src/actions/wallet/wallet-connect/clot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ export const getWCClot = (): Wallet => {
walletType: WalletType.WC_CLOT_MOBILE,
formatNativeUrl: (appUrl, wcUri, os) => {
const plainAppUrl = appUrl.replaceAll("/", "").replaceAll(":", "");
const encoded = encodeURIComponent(wcUri);
const encoded = wcUri && encodeURIComponent(wcUri);
switch (os) {
case "ios":
case "ios": {
if (!encoded) return `${plainAppUrl}://wcV2`;
return `${plainAppUrl}://wcV2?${encoded}`;
default:
}
default: {
if (!encoded) return `${plainAppUrl}://wc`;
return `${plainAppUrl}://wc?uri=${encoded}`;
}
}
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const getWCCosmostation = (): Wallet => {
walletType: WalletType.WC_COSMOSTATION_MOBILE,
formatNativeUrl: (appUrl, wcUri, _os) => {
const plainAppUrl = appUrl.replaceAll("/", "").replaceAll(":", "");
if (!wcUri) return `${plainAppUrl}://wc`;
return `${plainAppUrl}://wc?${wcUri}`;
},
};
Expand Down
16 changes: 4 additions & 12 deletions packages/graz/src/actions/wallet/wallet-connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,12 @@ export const getWalletConnect = (params?: GetWalletConnectParams): Wallet => {
const { appUrl, formatNativeUrl } = params;
if (!isMobile()) return;
if (isAndroid()) {
if (!wcUri) {
window.open(appUrl.mobile.android, "_self", "noreferrer noopener");
} else {
const href = formatNativeUrl(appUrl.mobile.android, wcUri, "android");
window.open(href, "_self", "noreferrer noopener");
}
const href = formatNativeUrl(appUrl.mobile.android, wcUri, "android");
window.open(href, "_self", "noreferrer noopener");
}
if (isIos()) {
if (!wcUri) {
window.open(appUrl.mobile.ios, "_self", "noreferrer noopener");
} else {
const href = formatNativeUrl(appUrl.mobile.ios, wcUri, "ios");
window.open(href, "_self", "noreferrer noopener");
}
const href = formatNativeUrl(appUrl.mobile.ios, wcUri, "ios");
window.open(href, "_self", "noreferrer noopener");
}
};

Expand Down
14 changes: 10 additions & 4 deletions packages/graz/src/actions/wallet/wallet-connect/keplr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ export const getWCKeplr = (): Wallet => {
walletType: WalletType.WC_KEPLR_MOBILE,
formatNativeUrl: (appUrl, wcUri, os) => {
const plainAppUrl = appUrl.replaceAll("/", "").replaceAll(":", "");
const encoded = encodeURIComponent(wcUri);
const encoded = wcUri && encodeURIComponent(wcUri);
switch (os) {
case "ios":
case "ios": {
if (!encoded) return `${plainAppUrl}://wcV2`;
return `${plainAppUrl}://wcV2?${encoded}`;
case "android":
}
case "android": {
if (!encoded) return `${plainAppUrl}://wcV2#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;`;
return `${plainAppUrl}://wcV2?${encoded}#Intent;package=com.chainapsis.keplr;scheme=keplrwallet;end;`;
default:
}
default: {
if (!encoded) return `${plainAppUrl}://wc`;
return `${plainAppUrl}://wc?uri=${encoded}`;
}
}
},
};
Expand Down
14 changes: 10 additions & 4 deletions packages/graz/src/actions/wallet/wallet-connect/leap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ export const getWCLeap = (): Wallet => {
walletType: WalletType.WC_LEAP_MOBILE,
formatNativeUrl: (appUrl, wcUri, os) => {
const plainAppUrl = appUrl.replaceAll("/", "").replaceAll(":", "");
const encoded = encodeURIComponent(wcUri);
const encoded = wcUri && encodeURIComponent(wcUri);
switch (os) {
case "ios":
case "ios": {
if (!encoded) return `${plainAppUrl}://wcV2`;
return `${plainAppUrl}://wcV2?${encoded}`;
case "android":
}
case "android": {
if (!encoded) return `${plainAppUrl}://wcV2#Intent;package=io.leapwallet.cosmos;scheme=leapwallet;end;`;
return `${plainAppUrl}://wcV2?${encoded}#Intent;package=io.leapwallet.cosmos;scheme=leapwallet;end;`;
default:
}
default: {
if (!encoded) return `${plainAppUrl}://wc`;
return `${plainAppUrl}://wc?uri=${encoded}`;
}
}
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/graz/src/actions/wallet/wallet-connect/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export interface GetWalletConnectParams {
android: string;
};
};
formatNativeUrl: (appUrl: string, wcUri: string, os?: "android" | "ios") => string;
formatNativeUrl: (appUrl: string, wcUri?: string, os?: "android" | "ios") => string;
}

0 comments on commit 0d78a5f

Please sign in to comment.