Skip to content

Commit

Permalink
fix(data): 🐛 Safari/Webkit not handling new URL correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jojobyte committed Oct 28, 2023
1 parent 8ae8e30 commit 85ef37b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 66 deletions.
30 changes: 29 additions & 1 deletion src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,32 @@ export const PHRASE_REGEX = new RegExp(
export const ALIAS_REGEX = new RegExp(
/^[a-zA-Z0-9]{1,}$/
// Needs support added for Dashes, Underscores & Periods
)
)
export const DASH_URI_REGEX = new RegExp(
/^(?:web\+)?(?<protocol>dash)(?:\:)(?:\/\/)?(?<address>.+)?(?:[?])(?<params>.+)/,
'ig'
)


// const DASH_URI_REGEX = new RegExp(
// /(?<protocol>dash)(?:\:)(?:\/\/)?(?<address>X[1-9A-HJ-NP-Za-km-z]{33})?(?:[?])(?<params>.+)?$/,
// 'ig'
// )

// const DASH_URI_REGEX = new RegExp(
// /(?<protocol>dash)(?:\:)(?:\/\/)?(?<address>X[1-9A-HJ-NP-Za-km-z]{33})?(?:[?])(?<params>.+)?$/,
// 'ig'
// )

// const DASH_URI_REGEX = new RegExp(
// /^(?:web\+)?(?<protocol>dash)(?:\:)(?:\/\/)?(?<address>.+)?(?<params>(?:[?])([a-zA-Z_-]+)(?:[=])([a-zA-Z0-9,_\-]+)(?:[&])?)+/,
// 'ig'
// )

// ^((?:web\+)?dash:)(?:\/{0,2})?(.+)$
// (?:web\+dash:)?(?:\/{0,2})?(.+)
// ^(?:(web\+)?dash:)(?:\/{0,2})?(.+)$

// if (uri.match(/^((web\+)?dash:)(\/\/)?(.+)/ig)) {
// result = parseDashURI(uri)
// }
42 changes: 18 additions & 24 deletions src/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import {
DashPhrase,
} from '../imports.js'

import { DUFFS } from './constants.js'
import {
DUFFS,
DASH_URI_REGEX,
} from './constants.js'

// export async function walletSchema(
// phrase = 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong',
Expand Down Expand Up @@ -433,18 +436,19 @@ export function sortContactsByName(a, b) {

export function parseDashURI(uri) {
let result = {}
let parsedUri = new URL(uri)
let parsedUri = [
...uri.matchAll(DASH_URI_REGEX)
]?.[0]?.groups || {}
let searchParams = new URLSearchParams(parsedUri?.params || '')

console.log(
'parseDashURI',
parsedUri
parsedUri,
searchParams
)

let { searchParams, pathname } = parsedUri
let addr = pathname.replaceAll('//', '')

if (addr) {
result.address = addr
if (parsedUri?.address) {
result.address = parsedUri?.address
}

// let xkeyOrAddr = xprv || xpub || addr
Expand Down Expand Up @@ -501,13 +505,6 @@ export function parseAddressField(uri) {
result.address = uri
}

// ^((?:web\+)?dash:)(?:\/{0,2})?(.+)$
// (?:web\+dash:)?(?:\/{0,2})?(.+)
// ^(?:(web\+)?dash:)(?:\/{0,2})?(.+)$
// if (uri.match(/^((web\+)?dash:)(\/\/)?(.+)/ig)) {
// result = parseDashURI(uri)
// }

return result
}

Expand Down Expand Up @@ -559,17 +556,14 @@ export function generateShareURI(state, protocol = 'web+dash') {
}

let scope = claims.map(p => p[0]).join(',')
let searchParams = new URLSearchParams([
...claims,
['scope', scope]
])

console.log('Generate QR claims', claims, scope)
console.log('Generate QR claims', claims, scope, searchParams)

return new URL(
`${protocol}://?${
new URLSearchParams([
...claims,
['scope', scope]
])
}`
)
return `${protocol}://?${searchParams.toString()}`
}

export async function loadStore(store, callback) {
Expand Down
56 changes: 15 additions & 41 deletions src/rigs/add-contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,9 @@ export let addContactRig = (function (globals) {
</footer>
`,
generateQr: state => {
let shareURI = generateShareURI(state, 'web+dash')
let shareLink = shareURI.toString()
let shareLink = generateShareURI(state, 'web+dash')

return {
uri: shareURI,
link: shareLink,
svg: qrSvg(
shareLink,
Expand Down Expand Up @@ -319,43 +317,25 @@ export let addContactRig = (function (globals) {
}
}
if (event.target?.name === 'contactAlias') {
// let updatedAlias =
debounceAlias(state, event)
// console.log(
// 'debounced updated alias',
// updatedAlias,
// )
}
},
// handleChange: state => async event => {
// event.preventDefault()
// if (
// event?.target?.validity?.patternMismatch &&
// event?.target?.type !== 'checkbox'
// ) {
// let label = event.target?.previousElementSibling?.textContent?.trim()
// if (label) {
// event.target.setCustomValidity(`Invalid ${label}`)
// }
// } else {
// event.target.setCustomValidity('')
// }
// event.target.reportValidity()

// // console.log(
// // '+contact handleChange',
// // event,
// // event.target?.name,
// // event.target?.value
// // )
// },
handleClick: state => async event => {
let shareAside = appDialogs.addContact.element.querySelector(
let shareAside = state.elements?.dialog?.querySelector(
'fieldset.share > aside'
)
if (
shareAside.contains(event.target)
shareAside?.contains(event.target)
) {
if (
event.target?.nodeName.toLowerCase() === 'input' &&
event.target?.readOnly
) {
event.preventDefault()
event.stopPropagation()

event.target.select()
}
if (
event.target?.classList?.contains('copy') ||
event.target?.classList?.contains('icon-copy')
Expand All @@ -366,15 +346,15 @@ export let addContactRig = (function (globals) {
setClipboard(event)
}
if (
event.target?.nodeName === 'svg'
event.target?.nodeName.toLowerCase() === 'svg'
) {
event.preventDefault()
event.stopPropagation()

openBlobSVG(event.target)
}
if (
event.target?.parentElement?.nodeName === 'svg'
event.target?.parentElement?.nodeName.toLowerCase() === 'svg'
) {
event.preventDefault()
event.stopPropagation()
Expand All @@ -383,13 +363,7 @@ export let addContactRig = (function (globals) {
}
}
},
handleRender: state => {
// console.log(
// '+contact app state & wallets',
// appState,
// state,
// )
},
handleRender: state => {},
handleSubmit: state => async event => {
event.preventDefault()
event.stopPropagation()
Expand Down

0 comments on commit 85ef37b

Please sign in to comment.