-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: added purchase tokens button #148
base: dev
Are you sure you want to change the base?
Changes from all commits
2e22107
92848ee
65caf1b
8cf0187
8b23c86
8679ef5
58dd7b4
df2cb65
32a10e9
95dc9e3
20e356e
85c52b4
8934b9e
aecb348
6aed3e4
8fb2362
2a05775
a61f69e
e162eb3
3f47c10
39e0ca7
05a7c5f
e260869
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ build | |
web_modules | ||
node_modules | ||
.idea | ||
yarn-error.log |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script> | ||
import Button from '~/components/elements/button.svelte' | ||
import {openPopupForAccount} from '~/lib/token-purchase' | ||
import {activeSession, activeBlockchain} from '~/store' | ||
|
||
$: shouldDisplayButton = $activeBlockchain?.id === 'eos' | ||
|
||
let loadingPopup = false | ||
|
||
function handleBuyingTokens() { | ||
loadingPopup = true | ||
|
||
openPopupForAccount($activeSession?.auth?.actor) | ||
.catch((err) => { | ||
console.error(err) | ||
}) | ||
.finally(() => { | ||
loadingPopup = false | ||
}) | ||
} | ||
</script> | ||
|
||
<style type="scss"> | ||
.buy-tokens-button { | ||
display: flex; | ||
align-items: center; | ||
padding: 10px; | ||
} | ||
</style> | ||
|
||
{#if shouldDisplayButton} | ||
<div class="buy-tokens-button"> | ||
<Button on:action={handleBuyingTokens} style="primary"> | ||
{loadingPopup ? 'Loading...' : 'Buy Tokens'} | ||
</Button> | ||
</div> | ||
{/if} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import type {Name} from '@greymass/eosio' | ||
|
||
import {addToast} from '~/stores/toast' | ||
|
||
const creationServiceUrl = import.meta.env.SNOWPACK_PUBLIC_WHALESPLAINER_URL | ||
const unicoveUrl = import.meta.env.SNOWPACK_PUBLIC_UNICOVE_URL | ||
|
||
const tokenOrderUrl = `${creationServiceUrl}/api/tokens/order` | ||
|
||
export const openPopupForAccount = async (accountName: Name | undefined): Promise<void> => { | ||
let whalesplainerTokenOrderResponse | ||
let whalesplainerTokenOrder | ||
|
||
try { | ||
whalesplainerTokenOrderResponse = await fetch(tokenOrderUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
wallet_address: accountName?.toString(), | ||
account_reference: accountName?.toString(), | ||
fiat_code: 'USD', | ||
coin_code: 'EOS', | ||
return_url_on_success: unicoveUrl, | ||
}), | ||
}) | ||
|
||
whalesplainerTokenOrder = await whalesplainerTokenOrderResponse.json() | ||
|
||
console.log({whalesplainerTokenOrder}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove debug logging |
||
} catch (error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this throws the toast below will fire as well, possibly replacing this error message with a generic one about popups. Refactor this so that error handling only needs to happen once, preferably at the callsite and not side-effecting with a toast |
||
addToast({ | ||
title: 'An error occurred when creating your order.', | ||
message: error.message, | ||
}) | ||
} | ||
|
||
const checkoutUrl = whalesplainerTokenOrder?.data?.order?.checkout_url | ||
|
||
const popup = | ||
checkoutUrl && | ||
window.open( | ||
checkoutUrl, | ||
'targetWindow', | ||
`toolbar=no, | ||
location=no, | ||
status=no, | ||
menubar=no, | ||
scrollbars=yes, | ||
resizable=yes, | ||
width=400, | ||
height=600` | ||
)! | ||
if (popup) { | ||
popup.focus() | ||
} else { | ||
addToast({ | ||
title: 'Unable to open token purchase popup.', | ||
message: 'Please make sure that popups are allowed for this website.', | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -909,6 +909,16 @@ | |
minimatch "^3.0.4" | ||
strip-json-comments "^3.1.1" | ||
|
||
"@greymass/create-account@^0.0.9": | ||
version "0.0.9" | ||
resolved "https://registry.yarnpkg.com/@greymass/create-account/-/create-account-0.0.9.tgz#1f41b00e33508396fa3ece2f431213c80cfd9d7a" | ||
integrity sha512-cWzqB5fYHmT5f5V5Kfgu/vF98+5YBIH4hk0XzsfbkC2FqoVy+918fpMx12gx654Effnc8q5stIdluDm/dnjlHw== | ||
dependencies: | ||
"@greymass/eosio" "^0.6.0" | ||
"@greymass/return-path" "^0.0.1" | ||
eosio-signing-request "^2.3.1" | ||
tslib "^2.1.0" | ||
|
||
"@greymass/[email protected]": | ||
version "0.7.0" | ||
resolved "https://registry.yarnpkg.com/@greymass/eosio-resources/-/eosio-resources-0.7.0.tgz#41425a22434818dd5caf175a4ffb0feab29fed0b" | ||
|
@@ -936,6 +946,13 @@ | |
dependencies: | ||
tslib "^2.1.0" | ||
|
||
"@greymass/return-path@^0.0.1": | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/@greymass/return-path/-/return-path-0.0.1.tgz#bcf4e74671af06d22ecd95dcdadb94efaa5adf78" | ||
integrity sha512-PMPgSJYSHeaYXbURj4JfsEeReWkJqlTKFMn2iTPhvb+6ICR5GhVPDJKewqZPqpZumcD13M1c701YYWKHZlMsxw== | ||
dependencies: | ||
tslib "^2.1.0" | ||
|
||
"@humanwhocodes/config-array@^0.5.0": | ||
version "0.5.0" | ||
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.5.0.tgz#1407967d4c6eecd7388f83acf1eaf4d0c6e58ef9" | ||
|
@@ -2035,7 +2052,7 @@ entities@^2.0.0: | |
resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55" | ||
integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A== | ||
|
||
eosio-signing-request@^2.2.0: | ||
eosio-signing-request@^2.2.0, eosio-signing-request@^2.3.1: | ||
version "2.4.0" | ||
resolved "https://registry.yarnpkg.com/eosio-signing-request/-/eosio-signing-request-2.4.0.tgz#87e89d4e016a6317e249dc3cc571390a9c2940d3" | ||
integrity sha512-jmFAzdXDfuDELN2Xvr857cm/TA0pb9lCoHQvRq9Gb/yp0GfIqWHhJuVyZyLkCHlU2E62rnID7es12qNFmn2l2g== | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this to accept undefined, make this a burden of the caller