Skip to content

Commit

Permalink
🚸 Skip session approval for in-app-browser
Browse files Browse the repository at this point in the history
  • Loading branch information
nwingt committed Oct 13, 2023
1 parent ce27ff2 commit bdd3f54
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
3 changes: 3 additions & 0 deletions app/models/wallet-connect-client/wallet-connect-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export const WalletConnectClientModel = types
const { peerMeta } = self.connector
return COMMON_API_CONFIG.userAgent.includes(peerMeta.name)
},
get version() {
return 1
},
}))
.views(self => ({
shouldShowWalletConnectModal(payload: any) {
Expand Down
13 changes: 9 additions & 4 deletions app/models/wallet-connect-v2-client/wallet-connect-v2-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx'
import { DirectSignResponse } from '@cosmjs/proto-signing'

import { logError } from '../../utils/error'
import { checkIsInAppBrowser } from '../../utils/wallet-connect';

import { withCurrentUser, withEnvironment, withNavigationStore } from '../extensions'

Expand All @@ -28,6 +29,9 @@ export const WalletConnectV2ClientModel = types
get isInAppBrowser() {
return false; // TODO: implement user agent checking
},
get version() {
return 2;
},
}))
.views(_ => ({
shouldShowWalletConnectModal(payload: any) {
Expand Down Expand Up @@ -247,7 +251,7 @@ export const WalletConnectV2ClientModel = types
method: 'session_proposal',
...proposal,
}
// if (!self.isInAppBrowser) {
if (!checkIsInAppBrowser(proposal)) {
// Show WalletConnect Modal for loading UX
self.navigationStore.navigateTo({
routeName: 'App',
Expand All @@ -259,10 +263,11 @@ export const WalletConnectV2ClientModel = types
},
}),
})
// }
} else {
// Approve session request directly without user's interaction
self.approveSessionRequest(proposal)
}

// Approve session request directly without user's interaction
// self.approveSessionRequest(proposal)
},
}))
.actions(self => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { WalletConnectStore } from "../../models/wallet-connect-store"

import { color } from "../../theme"
import { translate } from "../../i18n"
import { checkIsInAppBrowser } from "../../utils/wallet-connect"

import { Button } from "../../components/button"
import { LoadingLikeCoin } from "../../components/loading-likecoin"
Expand Down Expand Up @@ -93,7 +94,18 @@ export class WalletConnectRequestScreen extends React.Component<WalletConnectReq
this.close()
await this.requestor.approveRequest(this.payload, this.peerId)

if (this.requestor.isInAppBrowser) return;
switch (this.requestor.version) {
case 1:
if (this.requestor.isInAppBrowser) return;
break;

case 2:
if (checkIsInAppBrowser(this.payload)) return;
break;

default:
break;
}

// Show return to browser hint
let hintMessageKey: string
Expand Down
9 changes: 9 additions & 0 deletions app/utils/wallet-connect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { SignClientTypes } from "@walletconnect/types"

import { COMMON_API_CONFIG } from "../services/api/api-config"

export function checkIsInAppBrowser(payload: SignClientTypes.EventArguments['session_proposal']) {
return COMMON_API_CONFIG.userAgent.includes(
payload.params.proposer.metadata.name
)
}

0 comments on commit bdd3f54

Please sign in to comment.