Skip to content

Commit

Permalink
fix: be able to connect within iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
CedrikNikita authored and kenodressel committed Aug 25, 2023
1 parent c9affa0 commit e716371
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Header from '@/components/Header.vue';
import NavigationMenu from '@/components/NavigationMenu.vue';
import ConnectionStatus from '@/components/ConnectionStatus.vue';
import { isDexBackendDisabled } from '@/lib/utils';
import { IN_FRAME } from '@/lib/constants';
export default {
components: {
Expand Down Expand Up @@ -67,7 +68,7 @@ export default {
}
this.$store.commit('setIsSdkInitializing', true);
try {
if (this.$isMobile) {
if (this.$isMobile && !IN_FRAME) {
await this.$store.dispatch('initUniversal'); // TODO: remove after https://github.com/aeternity/aepp-sdk-js/issues/1390 is resolved
this.$store.dispatch('parseAndSendTransactionFromQuery');
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/components/ConnectWalletModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import {
WalletDetector, BrowserWindowMessageConnection,
} from '@aeternity/aepp-sdk';
import { resolveWithTimeout } from '../lib/utils';
import { IN_FRAME } from '../lib/constants';
import ModalDefault from './ModalDefault.vue';
import ButtonDefault from './ButtonDefault.vue';
import ButtonPlain from './ButtonPlain.vue';
Expand Down Expand Up @@ -137,7 +138,7 @@ export default {
};
},
async mounted() {
if (this.$isMobile) {
if (this.$isMobile && !IN_FRAME) {
this.addDefaultWallet();
} else {
this.scanningForWallets = true;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export const IS_MOBILE = window.navigator.userAgent.includes('Mobi');

export const IN_FRAME = window.parent !== window;

export const MAGNITUDE = 18;
// TODO: this is what uniswap uses as minimumLiquidity, let's decide on it
export const MINIMUM_LIQUIDITY = 1000n;
Expand Down
6 changes: 4 additions & 2 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
} from '@/lib/utils';
import {
DEFAULT_NETWORKS,
IN_FRAME,
IS_MOBILE,
} from '@/lib/constants';
import aeternityModule from './modules/aeternity';
import dexBackendModule from './modules/dexBackend';
Expand Down Expand Up @@ -161,7 +163,7 @@ export default createStore({
commit('setConnectingToWallet', true);
commit('setWallet', wallet);

if (window.navigator.userAgent.includes('Mobi') || isSafariBrowser()) {
if ((IS_MOBILE || isSafariBrowser()) && !IN_FRAME) {
if (address) {
commit('setConnectingToWallet', false);
return;
Expand All @@ -175,7 +177,7 @@ export default createStore({
} else {
try {
await resolveWithTimeout(30000, async () => {
const webWalletTimeout = window.navigator.userAgent.toLowerCase().includes('mobi') ? 0
const webWalletTimeout = IS_MOBILE ? 0
: setTimeout(() => commit('enableIframeWallet'), 15000);
commit('useSdkWallet');

Expand Down
4 changes: 3 additions & 1 deletion src/store/plugins/connectionStatusTracker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { IS_MOBILE } from '@/lib/constants';

export default (store) => {
const connectionStatusHandler = () => {
if (store.state.onLine !== navigator.onLine) store.commit('setOnLine', navigator.onLine);
if (!navigator.onLine && !window.navigator.userAgent.includes('Mobi')) {
if (!navigator.onLine && !IS_MOBILE) {
store.dispatch('modals/open', {
name: 'connection-status',
text: 'You are offline... Please check your connection.',
Expand Down

0 comments on commit e716371

Please sign in to comment.