Skip to content

Commit

Permalink
Merge pull request #2410 from ripcurlx/add-utm-parameters-for-website…
Browse files Browse the repository at this point in the history
…-links

Add utm parameters to bisq.network links
  • Loading branch information
ManfredKarrer authored Feb 12, 2019
2 parents fdafb1c + eb2e1a9 commit d1faa84
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 21 deletions.
1 change: 1 addition & 0 deletions desktop/src/main/java/bisq/desktop/main/MainViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public MainViewModel(BisqSetup bisqSetup,
BalanceWithConfirmationTextField.setWalletService(btcWalletService);

GUIUtil.setFeeService(feeService);
GUIUtil.setPreferences(preferences);

setupHandlers();
bisqSetup.addBisqSetupCompleteListener(this);
Expand Down
41 changes: 39 additions & 2 deletions desktop/src/main/java/bisq/desktop/util/GUIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,16 @@ public class GUIUtil {
public final static int AMOUNT_DECIMALS = 4;

private static FeeService feeService;
private static Preferences preferences;

public static void setFeeService(FeeService feeService) {
GUIUtil.feeService = feeService;
}

public static void setPreferences(Preferences preferences) {
GUIUtil.preferences = preferences;
}

public static double getScrollbarWidth(Node scrollablePane) {
Node node = scrollablePane.lookup(".scroll-bar");
if (node instanceof ScrollBar) {
Expand Down Expand Up @@ -586,22 +591,54 @@ public static void updateConfidence(TransactionConfidence confidence, Tooltip to


public static void openWebPage(String target) {

if (target.contains("bisq.network")) {
// add utm parameters
target = appendURI(target, "utm_source=desktop-client&utm_medium=in-app-link&utm_campaign=language_" +
preferences.getUserLanguage());
}

String key = "warnOpenURLWhenTorEnabled";
if (DontShowAgainLookup.showAgain(key)) {
final String finalTarget = target;
new Popup<>().information(Res.get("guiUtil.openWebBrowser.warning", target))
.actionButtonText(Res.get("guiUtil.openWebBrowser.doOpen"))
.onAction(() -> {
DontShowAgainLookup.dontShowAgain(key, true);
doOpenWebPage(target);
doOpenWebPage(finalTarget);
})
.closeButtonText(Res.get("guiUtil.openWebBrowser.copyUrl"))
.onClose(() -> Utilities.copyToClipboard(target))
.onClose(() -> Utilities.copyToClipboard(finalTarget))
.show();
} else {
doOpenWebPage(target);
}
}

private static String appendURI(String uri, String appendQuery) {
try {
final URI oldURI = new URI(uri);

String newQuery = oldURI.getQuery();

if (newQuery == null) {
newQuery = appendQuery;
} else {
newQuery += "&" + appendQuery;
}

URI newURI = new URI(oldURI.getScheme(), oldURI.getAuthority(), oldURI.getPath(),
newQuery, oldURI.getFragment());

return newURI.toString();
} catch (URISyntaxException e) {
e.printStackTrace();
log.error(e.getMessage());

return uri;
}
}

private static void doOpenWebPage(String target) {
try {
Utilities.openURI(new URI(target));
Expand Down
75 changes: 56 additions & 19 deletions desktop/src/test/java/bisq/desktop/util/GUIUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,51 @@
import bisq.core.locale.GlobalSettings;
import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
import bisq.core.user.DontShowAgainLookup;
import bisq.core.user.Preferences;

import bisq.common.util.Utilities;

import javafx.util.StringConverter;

import java.net.URI;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static bisq.desktop.maker.CurrencyListItemMakers.bitcoinItem;
import static bisq.desktop.maker.CurrencyListItemMakers.euroItem;
import static bisq.desktop.maker.CurrencyListItemMakers.numberOfTrades;
import static bisq.desktop.maker.PreferenceMakers.empty;
import static bisq.desktop.maker.TradeCurrencyMakers.bitcoin;
import static bisq.desktop.maker.TradeCurrencyMakers.euro;
import static com.natpryce.makeiteasy.MakeItEasy.make;
import static com.natpryce.makeiteasy.MakeItEasy.with;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;



import org.mockito.ArgumentCaptor;

@RunWith(PowerMockRunner.class)
@PrepareForTest({Utilities.class, Preferences.class})
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*"})
public class GUIUtilTest {

@Before
public void setup() {
Locale.setDefault(new Locale("en", "US"));
GlobalSettings.setLocale(new Locale("en", "US"));
Res.setBaseCurrencyCode("BTC");
Res.setBaseCurrencyName("Bitcoin");
}

// @Christoph: not sure if that was removed with intentions in the release branch.
// I leave it here commented out in case it happened due a merge mistake.
/*
@Test
public void testTradeCurrencyConverter() {
Map<String, Integer> offerCounts = new HashMap<String, Integer>() {{
Expand All @@ -68,16 +82,39 @@ public void testTradeCurrencyConverter() {
}

@Test
public void testCurrencyListWithOffersConverter() {
Res.setBaseCurrencyCode("BTC");
Res.setBaseCurrencyName("Bitcoin");
StringConverter<CurrencyListItem> currencyListItemConverter = GUIUtil.getCurrencyListItemConverter(Res.get("shared.oneOffer"),
Res.get("shared.multipleOffers"),
empty);
public void testOpenURLWithCampaignParameters() throws Exception {
Preferences preferences = mock(Preferences.class);
DontShowAgainLookup.setPreferences(preferences);
GUIUtil.setPreferences(preferences);
when(preferences.showAgain("warnOpenURLWhenTorEnabled")).thenReturn(false);
when(preferences.getUserLanguage()).thenReturn("en");

assertEquals("✦ Bitcoin (BTC) - 10 offers", currencyListItemConverter.toString(make(bitcoinItem.but(with(numberOfTrades, 10)))));
assertEquals("★ Euro (EUR) - 0 offers", currencyListItemConverter.toString(make(euroItem)));
assertEquals("★ Euro (EUR) - 1 offer", currencyListItemConverter.toString(make(euroItem.but(with(numberOfTrades, 1)))));
PowerMockito.mockStatic(Utilities.class);
ArgumentCaptor<URI> captor = ArgumentCaptor.forClass(URI.class);
PowerMockito.doNothing().when(Utilities.class, "openURI", captor.capture());

}*/
GUIUtil.openWebPage("https://bisq.network");

assertEquals("https://bisq.network?utm_source=desktop-client&utm_medium=in-app-link&utm_campaign=language_en", captor.getValue().toString());

GUIUtil.openWebPage("https://docs.bisq.network/trading-rules.html#f2f-trading");

assertEquals("https://docs.bisq.network/trading-rules.html?utm_source=desktop-client&utm_medium=in-app-link&utm_campaign=language_en#f2f-trading", captor.getValue().toString());
}

@Test
public void testOpenURLWithoutCampaignParameters() throws Exception {
Preferences preferences = mock(Preferences.class);
DontShowAgainLookup.setPreferences(preferences);
GUIUtil.setPreferences(preferences);
when(preferences.showAgain("warnOpenURLWhenTorEnabled")).thenReturn(false);

PowerMockito.mockStatic(Utilities.class);
ArgumentCaptor<URI> captor = ArgumentCaptor.forClass(URI.class);
PowerMockito.doNothing().when(Utilities.class, "openURI", captor.capture());

GUIUtil.openWebPage("https://www.github.com");

assertEquals("https://www.github.com", captor.getValue().toString());
}
}

0 comments on commit d1faa84

Please sign in to comment.