Skip to content

Commit

Permalink
Reuse @nimiq/utils RequestLink utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Nov 19, 2023
1 parent de9dd3d commit 13f5796
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import VueRouter, { RouteConfig, Route, NavigationGuardNext } from 'vue-router';
import Vue from 'vue';
import { createNimiqRequestLink, parseNimiqSafeRequestLink, NimiqRequestLinkType } from '@nimiq/utils';
import { Component } from 'vue-router/types/router.d';

import { provide, inject } from '@vue/composition-api';
Expand Down Expand Up @@ -334,18 +335,15 @@ const routes: RouteConfig[] = [{
}],
beforeEnter: (to, from, next) => {
if (from.fullPath === '/' && to.hash.startsWith('#_request/')) {
// old safe links are in this format: /#_request/NQ208P9L3YMDGQYT1TAA8D0GMC125HBQ1Q8A/100_
// new wallet links are in this format: /nimiq:NQ208P9L3YMDGQYT1TAA8D0GMC125HBQ1Q8A?amount=100
const results = to.hash.match(/^#_request\/(?<address>[A-Z0-9]+)\/?(?<amount>\d+)?_$/);
const address = results?.groups?.address;
const amount = results?.groups?.amount ? `?amount=${results.groups.amount}` : '';
next({
name: 'send-via-uri',
hash: `nimiq:${address}${amount}`,
replace: true,
const parsed = parseNimiqSafeRequestLink(window.location.href);
if (!parsed) return next();
const path = createNimiqRequestLink(parsed.recipient, {
...parsed,
type: NimiqRequestLinkType.URI,
});
return next({ path, replace: true });
} else {
next();
return next();
}
},
}, {
Expand Down

0 comments on commit 13f5796

Please sign in to comment.