Merge pull request #14102 from howard-stearns/account-managed-wallet-punchlist2

Account-managed wallet flow improvements
This commit is contained in:
John Conklin II 2018-10-01 16:43:01 -07:00 committed by GitHub
commit 878d2a6f25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 106 additions and 45 deletions

View file

@ -552,6 +552,10 @@ Rectangle {
// Alignment
horizontalAlignment: Text.AlignLeft;
verticalAlignment: Text.AlignVCenter;
onLinkActivated: {
// Only case is to go to the bank.
sendToScript({method: 'gotoBank'});
}
}
}
@ -1107,25 +1111,32 @@ Rectangle {
}
function handleBuyAgainLogic() {
// If you can buy this item again...
if (canBuyAgain()) {
// If you can't afford another copy of the item...
if (root.balanceAfterPurchase < 0) {
// If you already own the item...
if (root.alreadyOwned) {
buyText.text = "<b>Your Wallet does not have sufficient funds to purchase this item again.</b>";
// Else if you don't already own the item...
} else {
buyText.text = "<b>Your Wallet does not have sufficient funds to purchase this item.</b>";
}
buyTextContainer.color = "#FFC3CD";
buyTextContainer.border.color = "#F3808F";
buyGlyph.text = hifi.glyphs.alert;
buyGlyph.size = 54;
// If you CAN afford another copy of the item...
// General rules, implemented in various scattered places in this file:
// 1. If you already own the item, a viewInMyPurchasesButton is visible,
// and the buyButton is visible (and says "Buy it again") ONLY if it is a type you canBuyAgain.
// 2. Separately,
// a. If you don't have enough money to buy, the buyText becomes visible and tells you, and the buyButton is disabled.
// b. Otherwise, if the item is a content set and you don't have rez permission, the buyText becomes visible and tells you so.
// If you can't afford another copy of the item...
if (root.balanceAfterPurchase < 0) {
// If you already own the item...
if (!root.alreadyOwned) {
buyText.text = "<b>Your Wallet does not have sufficient funds to purchase this item.</b>";
// Else if you don't already own the item...
} else if (canBuyAgain()) {
buyText.text = "<b>Your Wallet does not have sufficient funds to purchase this item again.</b>";
} else {
handleContentSets();
buyText.text = "<b>While you do not have sufficient funds to buy this, you already have this item.</b>"
}
buyText.text += " Visit <a href='#'>Bank of High Fidelity</a> to get more HFC."
buyTextContainer.color = "#FFC3CD";
buyTextContainer.border.color = "#F3808F";
buyGlyph.text = hifi.glyphs.alert;
buyGlyph.size = 54;
// If you CAN afford another copy of the item...
} else {
handleContentSets();
}
}

View file

@ -829,6 +829,7 @@ Rectangle {
Commerce.getWalletAuthenticatedStatus(); // before writing security image, ensures that salt/account password is set.
Commerce.chooseSecurityImage(securityImagePath);
Commerce.generateKeyPair();
followReferrer({ referrer: walletSetup.referrer });
}
function addLeadingZero(n) {
@ -836,7 +837,7 @@ Rectangle {
}
function followReferrer(msg) {
if (msg.referrer === '' || msg.referrer === 'marketplace cta') {
if (msg.referrer === '') {
root.activeView = "initialize";
Commerce.getWalletStatus();
} else if (msg.referrer === 'purchases') {

View file

@ -28,7 +28,7 @@ Item {
property string activeView: "step_1";
property string lastPage;
property bool hasShownSecurityImageTip: false;
property string referrer;
property string referrer: '';
property string keyFilePath;
property date startingTimestamp;
property string setupAttemptID;

View file

@ -42,8 +42,7 @@ function AppUi(properties) {
that.additionalAppScreens = [];
that.checkIsOpen = function checkIsOpen(type, tabletUrl) { // Are we active? Value used to set isOpen.
// Actual url may have prefix or suffix.
return (type === that.currentVisibleScreenType) &&
that.currentVisibleUrl &&
return that.currentVisibleUrl &&
((that.home.indexOf(that.currentVisibleUrl) > -1) ||
(that.additionalAppScreens.indexOf(that.currentVisibleUrl) > -1));
};

View file

@ -96,7 +96,7 @@
});
}
var emitWalletSetupEvent = function () {
emitWalletSetupEvent = function () {
EventBridge.emitWebEvent(JSON.stringify({
type: "WALLET_SETUP"
}));

View file

@ -88,6 +88,49 @@ function setTabletVisibleInSecondaryCamera(visibleInSecondaryCam) {
function openWallet() {
ui.open(MARKETPLACE_WALLET_QML_PATH);
}
function setupWallet(referrer) {
// Needs to be done within the QML page in order to get access to QmlCommerce
openWallet();
var ALLOWANCE_FOR_EVENT_BRIDGE_SETUP = 0;
Script.setTimeout(function () {
ui.tablet.sendToQml({
method: 'updateWalletReferrer',
referrer: referrer
});
}, ALLOWANCE_FOR_EVENT_BRIDGE_SETUP);
}
function onMarketplaceOpen(referrer) {
var cta = referrer, match;
if (Account.loggedIn && walletNeedsSetup()) {
if (referrer === MARKETPLACE_URL_INITIAL) {
setupWallet('marketplace cta');
} else {
match = referrer.match(/\/item\/(\w+)$/);
if (match && match[1]) {
setupWallet(match[1]);
} else if (referrer.indexOf(METAVERSE_SERVER_URL) === -1) { // not a url
setupWallet(referrer);
} else {
print("WARNING: opening marketplace to", referrer, "without wallet setup.");
}
}
}
}
function openMarketplace(optionalItemOrUrl) {
// This is a bit of a kluge, but so is the whole file.
// If given a whole path, use it with no cta.
// If given an id, build the appropriate url and use the id as the cta.
// Otherwise, use home and 'marketplace cta'.
// AND... if call onMarketplaceOpen to setupWallet if we need to.
var url = optionalItemOrUrl || MARKETPLACE_URL_INITIAL;
// If optionalItemOrUrl contains the metaverse base, then it's a url, not an item id.
if (optionalItemOrUrl && optionalItemOrUrl.indexOf(METAVERSE_SERVER_URL) === -1) {
url = MARKETPLACE_URL + '/items/' + optionalItemOrUrl;
}
ui.open(url, MARKETPLACES_INJECT_SCRIPT_URL);
}
// Function Name: wireQmlEventBridge()
//
@ -134,10 +177,14 @@ function setCertificateInfo(currentEntityWithContextOverlay, itemCertificateId)
function onUsernameChanged() {
if (onMarketplaceScreen) {
ui.open(MARKETPLACE_URL_INITIAL, MARKETPLACES_INJECT_SCRIPT_URL);
openMarketplace();
}
}
function walletNeedsSetup() {
return Wallet.walletStatus === 1;
}
function sendCommerceSettings() {
ui.sendToHtml({
type: "marketplaces",
@ -145,7 +192,7 @@ function sendCommerceSettings() {
data: {
commerceMode: Settings.getValue("commerce", true),
userIsLoggedIn: Account.loggedIn,
walletNeedsSetup: Wallet.walletStatus === 1,
walletNeedsSetup: walletNeedsSetup(),
metaverseServerURL: Account.metaverseServerURL,
messagesWaiting: shouldShowDot
}
@ -626,6 +673,8 @@ var filterText; // Used for updating Purchases QML
function onWebEventReceived(message) {
message = JSON.parse(message);
if (message.type === GOTO_DIRECTORY) {
// This is the chooser between marketplaces. Only OUR markteplace
// requires/makes-use-of wallet, so doesn't go through openMarketplace bottleneck.
ui.open(MARKETPLACES_URL, MARKETPLACES_INJECT_SCRIPT_URL);
} else if (message.type === QUERY_CAN_WRITE_ASSETS) {
ui.sendToHtml(CAN_WRITE_ASSETS + " " + Entities.canWriteAssets());
@ -667,12 +716,7 @@ function onWebEventReceived(message) {
} else if (message.type === "LOGIN") {
openLoginWindow();
} else if (message.type === "WALLET_SETUP") {
wireQmlEventBridge(true);
ui.tablet.sendToQml({
method: 'updateWalletReferrer',
referrer: "marketplace cta"
});
openWallet();
setupWallet('marketplace cta');
} else if (message.type === "MY_ITEMS") {
referrerURL = MARKETPLACE_URL_INITIAL;
filterText = "";
@ -780,6 +824,14 @@ var onQmlMessageReceived = function onQmlMessageReceived(message) {
return;
}
switch (message.method) {
case 'gotoBank':
ui.close();
if (Account.metaverseServerURL.indexOf("staging") >= 0) {
Window.location = "hifi://hifiqa-master-metaverse-staging"; // So that we can test in staging.
} else {
Window.location = "hifi://BankOfHighFidelity";
}
break;
case 'purchases_openWallet':
case 'checkout_openWallet':
case 'checkout_setUpClicked':
@ -802,7 +854,7 @@ var onQmlMessageReceived = function onQmlMessageReceived(message) {
openWallet();
break;
case 'checkout_cancelClicked':
ui.open(MARKETPLACE_URL + '/items/' + message.params, MARKETPLACES_INJECT_SCRIPT_URL);
openMarketplace(message.params);
break;
case 'header_goToPurchases':
case 'checkout_goToPurchases':
@ -811,15 +863,15 @@ var onQmlMessageReceived = function onQmlMessageReceived(message) {
ui.open(MARKETPLACE_PURCHASES_QML_PATH);
break;
case 'checkout_itemLinkClicked':
ui.open(MARKETPLACE_URL + '/items/' + message.itemId, MARKETPLACES_INJECT_SCRIPT_URL);
openMarketplace(message.itemId);
break;
case 'checkout_continueShopping':
ui.open(MARKETPLACE_URL_INITIAL, MARKETPLACES_INJECT_SCRIPT_URL);
openMarketplace();
break;
case 'purchases_itemInfoClicked':
var itemId = message.itemId;
if (itemId && itemId !== "") {
ui.open(MARKETPLACE_URL + '/items/' + itemId, MARKETPLACES_INJECT_SCRIPT_URL);
openMarketplace(itemId);
}
break;
case 'checkout_rezClicked':
@ -840,20 +892,20 @@ var onQmlMessageReceived = function onQmlMessageReceived(message) {
break;
case 'header_marketplaceImageClicked':
case 'purchases_backClicked':
ui.open(message.referrerURL, MARKETPLACES_INJECT_SCRIPT_URL);
openMarketplace(message.referrerURL);
break;
case 'purchases_goToMarketplaceClicked':
ui.open(MARKETPLACE_URL_INITIAL, MARKETPLACES_INJECT_SCRIPT_URL);
openMarketplace();
break;
case 'updateItemClicked':
ui.open(message.upgradeUrl + "?edition=" + message.itemEdition,
MARKETPLACES_INJECT_SCRIPT_URL);
openMarketplace(message.upgradeUrl + "?edition=" + message.itemEdition);
break;
case 'giftAsset':
break;
case 'passphrasePopup_cancelClicked':
case 'needsLogIn_cancelClicked':
// Should/must NOT check for wallet setup.
ui.open(MARKETPLACE_URL_INITIAL, MARKETPLACES_INJECT_SCRIPT_URL);
break;
case 'needsLogIn_loginClicked':
@ -883,7 +935,7 @@ var onQmlMessageReceived = function onQmlMessageReceived(message) {
ContextOverlay.requestOwnershipVerification(message.entity);
break;
case 'inspectionCertificate_showInMarketplaceClicked':
ui.open(message.marketplaceUrl, MARKETPLACES_INJECT_SCRIPT_URL);
openMarketplace(message.marketplaceUrl);
break;
case 'header_myItemsClicked':
referrerURL = MARKETPLACE_URL_INITIAL;
@ -1024,12 +1076,7 @@ var onTabletScreenChanged = function onTabletScreenChanged(type, url) {
onCommerceScreen = onCommerceScreenNow;
onWalletScreen = onWalletScreenNow;
onMarketplaceItemTesterScreen = onMarketplaceItemTesterScreenNow;
wireQmlEventBridge(
onMarketplaceScreen ||
onCommerceScreen ||
onWalletScreen ||
onMarketplaceItemTesterScreen);
wireQmlEventBridge(onCommerceScreen || onWalletScreen || onMarketplaceItemTesterScreen);
if (url === MARKETPLACE_PURCHASES_QML_PATH) {
// FIXME? Is there a race condition here in which the event
@ -1066,6 +1113,9 @@ var onTabletScreenChanged = function onTabletScreenChanged(type, url) {
isWired = true;
Wallet.refreshWalletStatus();
} else {
if (onMarketplaceScreen) {
onMarketplaceOpen('marketplace cta');
}
ui.tablet.sendToQml({
method: 'inspectionCertificate_resetCert'
});