Skip to content

Commit

Permalink
Deeplink: refactor (#319)
Browse files Browse the repository at this point in the history
* Fix "Repais bid"

* Improve UX

* PR comments

* Refactor deeplink

Co-authored-by: Chi Kei Chan <chikeichan@gmail.com>
  • Loading branch information
Falci and chikeichan committed Apr 18, 2021
1 parent 8723c0b commit 9a684c7
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 70 deletions.
30 changes: 30 additions & 0 deletions app/deeplink/index.js
@@ -0,0 +1,30 @@
import { setDeeplink } from '../ducks/app';
import { clientStub as aClientStub } from '../background/analytics/client';
const analytics = aClientStub(() => require('electron').ipcRenderer);
import { store } from '../store/configureStore';
import * as methods from './methods';

export default function handleDeeplink(message) {
const url = new URL(message);
const state = store.getState();
const isLocked = state.wallet.isLocked;

analytics.track('deeplink', {
pathname: url.pathname,
});

// pathname = "//method/"
const [method] = url.pathname.substr(2).split('/');
const handler = methods[method];

if (typeof handler === 'function') {
if (isLocked) {
store.dispatch(setDeeplink(message));
return;
}

methods[method](message);
} else {
console.error('Unknown deeplink:', message);
}
}
16 changes: 16 additions & 0 deletions app/deeplink/methods/fulfillauction.js
@@ -0,0 +1,16 @@
import { history } from '../../store/configureStore';

export default message => {
const url = new URL(message);
const params = url.searchParams;
const name = params.get('name');
const presignJSONString = params.get('presign');

if (presignJSONString) {
store.dispatch(setDeeplinkParams({ presignJSONString }));
}

if (name) {
history.push(`/exchange`);
}
};
4 changes: 4 additions & 0 deletions app/deeplink/methods/index.js
@@ -0,0 +1,4 @@
export { default as fulfillauction } from './fulfillauction';
export { default as openmanager } from './openmanager';
export { default as openname } from './openname';
export { default as updaterecord } from './updaterecord';
7 changes: 7 additions & 0 deletions app/deeplink/methods/openmanager.js
@@ -0,0 +1,7 @@
import { history } from '../../store/configureStore';

export default message => {
const name = new URL(message).searchParams.get('name');

history.push(`/domain_manager/${name}`);
};
7 changes: 7 additions & 0 deletions app/deeplink/methods/openname.js
@@ -0,0 +1,7 @@
import { history } from '../../store/configureStore';

export default message => {
const name = new URL(message).searchParams.get('name');

history.push(`/domain/${name}`);
};
14 changes: 14 additions & 0 deletions app/deeplink/methods/updaterecord.js
@@ -0,0 +1,14 @@
import { history, store } from '../../store/configureStore';
import { setDeeplinkParams } from '../../ducks/app';

export default message => {
const url = new URL(message);
const params = url.searchParams;
const name = params.get('name');
const txt = params.get('txt');

if (txt) {
store.dispatch(setDeeplinkParams({ txt }));
}
history.push(`/domain_manager/${name}`);
};
70 changes: 1 addition & 69 deletions app/index.js
Expand Up @@ -10,8 +10,7 @@ import { history, store } from './store/configureStore';
import './global.scss';
import { showError } from './ducks/notifications';
import {ipcRenderer} from "electron";
import { clientStub as aClientStub } from './background/analytics/client';
const analytics = aClientStub(() => require('electron').ipcRenderer);
import handleDeeplink from './deeplink'

window.addEventListener('error', (e) => {
store.dispatch(showError(e.message));
Expand All @@ -27,73 +26,6 @@ ipcRenderer.on('deeplink', (_, message) => {
handleDeeplink(message);
});

function handleDeeplink(message) {
const url = new URL(message);
const state = store.getState();
const isLocked = state.wallet.isLocked;
const params = url.searchParams;

analytics.track('deeplink', {
pathname: url.pathname,
});

let name, txt, presignJSONString;
switch (url.pathname) {
case "//updaterecord":
case "//updaterecord/":
name = params.get('name');
txt = params.get('txt');

if (txt) {
store.dispatch(setDeeplinkParams({ txt }));
}

if (isLocked) {
store.dispatch(setDeeplink(message));
} else {
history.push(`/domain_manager/${name}`);
}
return;
case "//openname":
case "//openname/":
name = params.get('name');

if (isLocked) {
store.dispatch(setDeeplink(message));
} else {
history.push(`/domain/${name}`);
}
return;
case "//openmanager":
case "//openmanager/":
name = params.get('name');

if (isLocked) {
store.dispatch(setDeeplink(message));
} else if (name) {
history.push(`/domain_manager/${name}`);
}
return;
case "//fulfillauction":
case "//fulfillauction/":
name = params.get('name');
presignJSONString = params.get('presign');

if (presignJSONString) {
store.dispatch(setDeeplinkParams({ presignJSONString }));
}

if (isLocked) {
store.dispatch(setDeeplink(message));
} else if (name) {
history.push(`/exchange`);
}
return;
default:
return;
}
}

history.listen(location => {
const state = store.getState();
const deeplink = state.app.deeplink;
Expand Down
2 changes: 1 addition & 1 deletion app/pages/Auction/RepairBid.js
Expand Up @@ -57,7 +57,7 @@ export class RepairBid extends Component {
return;

return this.verifyBid(parsed);
};
}

async verifyBid(value) {
const {bid} = this.props;
Expand Down

0 comments on commit 9a684c7

Please sign in to comment.