Skip to content

Commit

Permalink
better dev tooling for verify view
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronsutter committed Oct 31, 2019
1 parent 7a8d607 commit 6c05892
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 30 deletions.
1 change: 0 additions & 1 deletion bin/buy.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<div class="gumroad-product-embed" data-gumroad-product-id="fgSJ">
<p id='loadingP'></p>
</div>
<script src="common.bundle.js"></script>
<script src='buy.js'></script>
</body>
</html>
1 change: 0 additions & 1 deletion bin/verify.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
</head>
<body>
<div id='verify__react__root'></div>
<script src="common.bundle.js"></script>
<script src="verify.bundle.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion example.pltr
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@
"dirty": true,
"fileName": "/Users/sparrowhawk/github/plottr_electron/example.pltr",
"loaded": true,
"version": "1.4.24"
"version": "1.4.26"
},
"lines": [
{
Expand Down
7 changes: 5 additions & 2 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,14 @@
"Hide Plottr": {
"message": "Hide Plottr"
},
"Hmmmm. It looks like that's not a valid license key": {
"message": "Hmmmm. It looks like that's not a valid license key"
},
"If you keep seeing this problem, email me at [email protected]": {
"message": "If you keep seeing this problem, email me at [email protected]"
},
"It looks like you have Plottr on 5 computers already or you requested a refund": {
"message": "It looks like you have Plottr on 5 computers already or you requested a refund"
"It looks like you have Plottr on 5 computers already": {
"message": "It looks like you have Plottr on 5 computers already"
},
"It looks like you have an older file version. This could make things work funky or not at all. May Plottr update it for you?": {
"message": "It looks like you have an older file version. This could make things work funky or not at all. May Plottr update it for you?"
Expand Down
8 changes: 4 additions & 4 deletions locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@
"Hide Plottr": {
"message": "Cacher Plottr"
},
"Hmmmm. It looks like that's not a valid license key.": {
"message": "Hmmm. Il semble que ce n'est pas une clef de licence valable."
"Hmmmm. It looks like that's not a valid license key": {
"message": "Hmmm. Il semble que ce n'est pas une clef de licence valable"
},
"If you keep seeing this problem, email me at [email protected]": {
"message": "Si le problème se répète, merci de m''écrire à [email protected]"
},
"It looks like you have Plottr on 5 computers already or you requested a refund": {
"message": "Il semble que vous avez installé Plottr sur 5 ordinateurs ou que vous vous êtes fait rembourser."
"It looks like you have Plottr on 5 computers already": {
"message": "Il semble que vous avez installé Plottr sur 5 ordinateurs"
},
"It looks like you have an older file version. This could make things work funky or not at all. May Plottr update it for you?": {
"message": "Il semble que vous avez une version ancienne du fichier. Le logiciel pourrait fonctionner étrangement ou pas du tout. Plottr peut-il faire une mise à jour pour vous?"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"repository": "https://github.com/cameronsutter/plottr_electron.git",
"private": true,
"readme": "Copyright 2016 C. Louis S. (Cameron Sutter)",
"version": "1.4.26",
"version": "1.4.27",
"author": {
"name": "C. Louis S.",
"email": "[email protected]",
Expand Down
61 changes: 41 additions & 20 deletions src/verify/VerifyView.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import i18n from 'format-message'
const SUCCESS = 'success'
const OFFLINE = 'offline'
const INVALID = 'invalid'
const TOOMANY = 'toomany'
const CANTSAVE = 'cantsave'
const SAVE2 = 'save_attempt_2'
const RED = 'bg-danger'
Expand All @@ -33,8 +34,9 @@ class VerifyView extends Component {
} else if (value === OFFLINE) {
return i18n("It looks like you're not online. You don't always have to be online to user Plottr, but it can't verify your license offline")
} else if (value === INVALID) {
return i18n('It looks like you have Plottr on 5 computers already or you requested a refund')
// return i18n("Hmmmm. It looks like that's not a valid license key.")
return i18n("Hmmmm. It looks like that's not a valid license key")
} else if (value === TOOMANY) {
return i18n('It looks like you have Plottr on 5 computers already')
} else if (value === CANTSAVE) {
return i18n("Plottr verified your license key successfully, but there was an error saving that. Let's try one more time")
} else if (value === SAVE2) {
Expand All @@ -44,7 +46,11 @@ class VerifyView extends Component {
}
}

verifyLicense (license) {
isValidLicense = (body) => {
return body.success && !body.purchase.refunded && !body.purchase.chargebacked && !body.purchase.disputed
}

verifyLicense = (license) => {
var req = {
url: 'https://api.gumroad.com/v2/licenses/verify',
method: 'POST',
Expand All @@ -54,31 +60,46 @@ class VerifyView extends Component {
license_key: license
}
}
if (process.env.NODE_ENV === 'development') {
req.body.increment_uses_count = 'false'
}
const view = this
request(req, function (err, response, body) {
var newState = {spinnerHidden: true}
if (err && err.code === 404) {
newState.showAlert = true
newState.alertText = view.makeAlertText(INVALID)
} else {
if (body.success && !body.purchase.refunded && !body.purchase.chargebacked && body.uses <= 5) {
// save uses, purchase.email, purchase.full_name, purchase.variants
storage.set('user_info', body, function(err) {
if (err) {
view.setState({showAlert: true, alertText: view.makeAlertText(CANTSAVE)})
storage.set('user_info', body, function(err) {
if (err) {
view.setState({showAlert: true, alertText: view.makeAlertText(SAVE2)})
} else {
view.setState({showAlert: true, alertClass: GREEN, alertText: view.makeAlertText(SUCCESS)})
if (process.env.NODE_ENV === 'development') {
console.log(body)
}
if (view.isValidLicense(body)) {
if (body.uses > 5) {
newState.showAlert = true
newState.alertText = view.makeAlertText(TOOMANY)
} else {
// save uses, purchase.email, purchase.full_name, purchase.variants
storage.set('user_info', body, function(err) {
if (err) {
view.setState({showAlert: true, alertText: view.makeAlertText(CANTSAVE)})
storage.set('user_info', body, function(err) {
if (err) {
view.setState({showAlert: true, alertText: view.makeAlertText(SAVE2)})
} else {
view.setState({showAlert: true, alertClass: GREEN, alertText: view.makeAlertText(SUCCESS)})
if (process.env.NODE_ENV !== 'development') {
ipcRenderer.send('license-verified')
}
}
})
} else {
view.setState({showAlert: true, alertClass: GREEN, alertText: view.makeAlertText(SUCCESS)})
if (process.env.NODE_ENV !== 'development') {
ipcRenderer.send('license-verified')
}
})
} else {
view.setState({showAlert: true, alertClass: GREEN, alertText: view.makeAlertText(SUCCESS)})
ipcRenderer.send('license-verified')
}
})
}
}
})
}
} else {
newState.showAlert = true
newState.alertText = view.makeAlertText(INVALID)
Expand Down

0 comments on commit 6c05892

Please sign in to comment.