Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TAS-516] 🚸 Skip session approval for in-app-browser #398

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
}