/*
 * This file is part of bisq.
 *
 * bisq is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 *
 * bisq is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with bisq. If not, see <http://www.gnu.org/licenses/>.
 */

package io.bisq.gui.util;

import io.bisq.common.app.DevEnv;
import io.bisq.core.btc.wallet.WalletUtils;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.utils.MonetaryFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;

public class BsqFormatter extends BSFormatter {
    private static final Logger log = LoggerFactory.getLogger(BsqFormatter.class);
    @SuppressWarnings("PointlessBooleanExpression")
    private static final boolean useBsqAddressFormat = true || !DevEnv.DEV_MODE;
    private final String prefix = "B";

    @Inject
    private BsqFormatter() {
        super();
        // LTC based BSQ
        coinFormat = new MonetaryFormat().shift(3).code(3, "BSQ").minDecimals(5);

        // BTC based BSQ
        // coinFormat = new MonetaryFormat().shift(5).code(5, "BSQ").minDecimals(3);
    }

    /**
     * Returns the base-58 encoded String representation of this
     * object, including version and checksum bytes.
     */
    public String getBsqAddressStringFromAddress(Address address) {
        final String addressString = address.toString();
        if (useBsqAddressFormat)
            return prefix + addressString;
        else
            return addressString;

    }

    public Address getAddressFromBsqAddress(String encoded) {
        if (useBsqAddressFormat)
            encoded = encoded.substring(prefix.length(), encoded.length());

        try {
            return Address.fromBase58(WalletUtils.getParameters(), encoded);
        } catch (AddressFormatException e) {
            log.error(e.toString());
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}

@@ -736,16 +736,57 @@
 DevEnv;%0A
+import io.bisq.core.app.BisqEnvironment;%0A
 import i
@@ -1374,16 +1374,47 @@
 rmatter(
+BisqEnvironment bisqEnvironment
 ) %7B%0A    
@@ -1426,24 +1426,25 @@
 uper();%0A
+%0A
         
 // LTC b
@@ -1439,25 +1439,305 @@
     
-// LTC based BSQ%0A
+final String baseCurrencyCode = bisqEnvironment.getBaseCurrencyNetwork().getCurrencyCode();%0A        switch (baseCurrencyCode) %7B%0A            case %22BTC%22:%0A                coinFormat = new MonetaryFormat().shift(5).code(5, %22BSQ%22).minDecimals(3);%0A                break;%0A            case %22LTC%22:%0A        
     
@@ -1814,25 +1814,24 @@
 als(5);%0A
-%0A
         
 // BTC b
@@ -1826,35 +1826,93 @@
     
-// BTC based BSQ%0A        //
+        break;%0A            case %22DOGE%22:%0A                // TODO check%0A               
  coi
@@ -1944,33 +1944,33 @@
 mat().shift(
-5
+3
 ).code(
-5
+3
 , %22BSQ%22).min
@@ -1974,27 +1974,195 @@
 minDecimals(
-3);
+5);%0A                break;%0A            default:%0A                throw new RuntimeException(%22baseCurrencyCode not defined. baseCurrencyCode=%22 + baseCurrencyCode);%0A        %7D
 %0A    %7D%0A%0A    

Make bsq format dynamic by base currency