Skip to content

Commit

Permalink
ELECTRON: UI: Add basic sell button
Browse files Browse the repository at this point in the history
  • Loading branch information
mjmacleod committed Mar 1, 2021
1 parent fed3828 commit 2051410
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/frontend/lite/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"buttons": {
"back": "Back",
"buy_gulden": "Buy Gulden",
"sell_gulden": "Sell Gulden",
"buy_your_first_gulden": "Buy your first Gulden",
"change_password": "Change password",
"clear": "Clear",
Expand Down
1 change: 1 addition & 0 deletions src/frontend/lite/src/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"buttons": {
"back": "Terug",
"buy_gulden": "Koop Gulden",
"sell_gulden": "Verkoop Gulden",
"buy_your_first_gulden": "Koop jouw eerste Gulden",
"change_password": "Verander wachtwoord",
"clear": "Wissen",
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/lite/src/unity/Controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ class BackendUtilities {
static GetBuySessionUrl() {
return handleError(ipc.sendSync("BackendUtilities.GetBuySessionUrl"));
}
static GetSellSessionUrl() {
return handleError(ipc.sendSync("BackendUtilities.GetSellSessionUrl"));
}
}

export { BackendUtilities };
Expand Down
25 changes: 25 additions & 0 deletions src/frontend/lite/src/unity/LibUnity.js
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,31 @@ class LibUnity {
event.returnValue = handleError(e);
}
});

ipc.on("BackendUtilities.GetSellSessionUrl", async event => {
console.log(`IPC: BackendUtilities.GetSellSessionUrl()`);
try {
var formData = new FormData();
formData.append("address", store.state.wallet.receiveAddress);
formData.append("currency", "gulden");
formData.append("uuid", this.walletController.GetUUID());

let response = await axios.post(
"https://www.blockhut.com/buysession.php",
formData,
{
headers: formData.getHeaders()
}
);

event.returnValue = {
success: response.data.status_message === "OK",
result: `https://blockhut.com/sell.php?sessionid=${response.data.sessionid}`
};
} catch (e) {
event.returnValue = handleError(e);
}
});
}
}

Expand Down
19 changes: 18 additions & 1 deletion src/frontend/lite/src/views/Account/SpendingAccount/Send.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
>
{{ $t("buttons.send") }}
</button>
<button @click="sellGulden" class="sell-gulden" :disabled="sellDisabled">
{{ $t("buttons.sell_gulden") }}
</button>
</div>
</div>
</template>
Expand All @@ -47,6 +50,7 @@ import { mapState } from "vuex";
import { LibraryController, AccountsController } from "@/unity/Controllers";
import ConfirmTransactionDialog from "./ConfirmTransactionDialog";
import EventBus from "@/EventBus";
import { BackendUtilities } from "@/unity/Controllers";
export default {
name: "Send",
Expand All @@ -58,7 +62,8 @@ export default {
password: null,
isAmountInvalid: false,
isAddressInvalid: false,
isPasswordInvalid: false
isPasswordInvalid: false,
sellDisabled: false
};
},
computed: {
Expand Down Expand Up @@ -109,6 +114,18 @@ export default {
EventBus.$off("transaction-succeeded", this.onTransactionSucceeded);
},
methods: {
async sellGulden() {
try {
this.sellDisabled = true;
let url = await BackendUtilities.GetSellSessionUrl();
if (!url) {
url = "https://gulden.com/sell";
}
window.open(url, "sell-gulden");
} finally {
this.sellDisabled = false;
}
},
onPasswordKeydown() {
this.isPasswordInvalid = false;
},
Expand Down

0 comments on commit 2051410

Please sign in to comment.