-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
412 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { TonicDialog } from '@socketsupply/components/dialog' | ||
|
||
class DialogAccount extends TonicDialog { | ||
constructor () { | ||
super() | ||
|
||
this.handleResponse = this.handleResponse.bind(this) | ||
} | ||
|
||
async show () { | ||
super.show() | ||
window.addEventListener('message', this.handleResponse, { once: true }) | ||
} | ||
|
||
async hide () { | ||
super.hide() | ||
window.removeEventListener('message', this.handleResponse) | ||
} | ||
|
||
async handleResponse (event) { | ||
const iframe = this.querySelector('iframe') | ||
if (event.source !== iframe.contentWindow) return | ||
|
||
const app = this.props.app | ||
|
||
if (!event.data.success) { | ||
console.error('Unsuccessful data returned', event) | ||
this.resolve(event.data) | ||
await this.hide() | ||
return | ||
} | ||
|
||
console.log('GOT RESPONSE FROM STRIPE PAGE', event.data) | ||
|
||
try { | ||
const res = await fetch('https://api.socketsupply.co/signup', { | ||
method: 'POST', | ||
mode: 'cors', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(event.data) | ||
}) | ||
|
||
console.log('SIGNUP RESPONSE', res) | ||
|
||
if (res.ok) { | ||
const { data: dataUser } = await this.db.state.get('user') | ||
dataUser.buildKeys = await res.json() | ||
console.log('dataUser', dataUser) | ||
await this.db.state.put('user', dataUser) | ||
await this.hide() | ||
} | ||
} catch (err) { | ||
if (err.name === "AbortError") { | ||
this.resolve({ data: event.data }) | ||
await this.hide() | ||
} | ||
console.log(err) | ||
} | ||
} | ||
|
||
async prompt () { | ||
await this.show() | ||
const { promise, resolve } = Promise.withResolvers() | ||
this.resolve = resolve | ||
return promise | ||
} | ||
|
||
render () { | ||
const src = `pages/account.html?dev=${process.env.DEV ? 'true' : 'false'}` | ||
|
||
return this.html` | ||
<header>Account</header> | ||
<main> | ||
<iframe src="${src}" border=0></iframe> | ||
</main> | ||
` | ||
} | ||
} | ||
|
||
export default DialogAccount | ||
export { DialogAccount } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
dialog-account { | ||
display: grid; | ||
grid-template-rows: auto 1fr 60px; | ||
max-width: 900px; | ||
min-width: 650px; | ||
min-height: 580px; | ||
display: grid; | ||
font-family: var(--tonic-monospace); | ||
text-align: center; | ||
} | ||
|
||
dialog-account header { | ||
height: 46px; | ||
text-align: center; | ||
padding: 14px; | ||
font-size: 12px; | ||
color: var(--tonic-info); | ||
app-region: drag; | ||
--app-region: drag; | ||
} | ||
|
||
dialog-account footer { | ||
height: 60px; | ||
display: grid; | ||
grid-template-columns: 1fr auto; | ||
gap: 12px; | ||
padding: 0 14px; | ||
} | ||
|
||
dialog-account tonic-button { | ||
app-region: unset; | ||
--app-region: unset; | ||
place-self: center end; | ||
} | ||
|
||
dialog-account p { | ||
margin: 0; | ||
} | ||
|
||
dialog-account main { | ||
justify-content: center; | ||
align-content: center; | ||
padding: 0 6%; | ||
} | ||
|
||
dialog-account main iframe { | ||
width: 100%; | ||
height: 100%; | ||
border: 0; | ||
app-region: initial; | ||
--app-region: initial; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.