Skip to content

Commit

Permalink
Bug patches & code improvement
Browse files Browse the repository at this point in the history
Directory rework to reduce impact & coupling on deployment
Adding basic support for native mobile support
Fixing french translation error
  • Loading branch information
gnock committed Jul 28, 2018
1 parent 2a85cf0 commit b454e8e
Show file tree
Hide file tree
Showing 22 changed files with 267 additions and 127 deletions.
4 changes: 2 additions & 2 deletions .gitignore
@@ -1,8 +1,8 @@
.idea/
*.iml
node_modules
src/api/cache*
src/api/lastRun.txt
src_api/cache*
src_api/lastRun.txt
src/**/*.js
src/**/*.js.map
!src/lib/*.js
Expand Down
24 changes: 24 additions & 0 deletions debug-router.php
@@ -0,0 +1,24 @@
<?php
/**
* Copyright (c) 2018, Gnock
* Copyright (c) 2018, The Masari Project
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

$requestUri = isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : '';

if(strpos($requestUri,'/api') === false){
return false;
}else{
$path = __DIR__.'/src_api/'.str_replace('/api/', '',$requestUri);
include $path;
}
38 changes: 29 additions & 9 deletions src/assets/css/main.css
Expand Up @@ -34,10 +34,13 @@ body.menuHidden{
}
}
@media screen and (max-width: 600px) {
onlyMobile{
.onlyMobile{
display: none;
}
}
body.transparent{
background: transparent !important;
}

.hidden{
display: none !important;
Expand All @@ -59,6 +62,11 @@ body.menuHidden{
display:none !important;
}

.native{}
body.native .hideOnNative{
display: none !important;
}

#topBar{
height:34px;line-height:34px;
position: fixed;
Expand Down Expand Up @@ -174,38 +182,42 @@ body.menuHidden #page,body.menuDisabled #page{
}
}

.copyright{
#copyright{
text-align: left;
padding:30px 0;
color: #474E5D;
font-size: 14px;
padding-left:10px;
margin-left:280px;
}
body.menuDisabled .copyright{
body.menuDisabled #copyright{
margin-left:0;
}
body.transparent #copyright{
display: none;
}
/* computer */
@media screen and (max-width: 600px) {
body.menuHidden .copyright{
body.menuHidden #copyright{
margin-left: 0;
}
}

.copyright a{color: #474E5D;text-decoration: none;}
.copyright .right{

#copyright a{color: #474E5D;text-decoration: none;}
#copyright .right{
float:right;
}
.copyright .right a, .copyright .right select{
#copyright .right a, #copyright .right select{
display:inline-block;
margin-right: 10px;
}
@media screen and (max-width: 800px) {
.copyright,.copyright .right{
#copyright,#copyright .right{
float:none;
text-align: center;
}
.copyright .right{
#copyright .right{
padding-top:10px;
}
}
Expand Down Expand Up @@ -374,6 +386,10 @@ body.menuDisabled .copyright{
-o-transition: all 0.4s;
transition: all 0.4s;
}
.qrCodeScanningContainer.native{
background: transparent !important;
display: none;
}
.qrCodeScanningContainer.hidden{
top:100vh;
display: block !important;
Expand All @@ -392,6 +408,10 @@ body.menuDisabled .copyright{
line-height: 35px;
text-align: center;
}
.qrCodeScanningContainer.native .close{
color:white;
border-color: white;
}
.qrCodeScanningContainer .close:hover {
background: black;
color: #146DBD;
Expand Down
21 changes: 10 additions & 11 deletions src/config.ts
@@ -1,16 +1,12 @@
let global : any = typeof window !== 'undefined' ? window : self;
global.config = {
apiUrl: "http://127.0.0.1:1984/",
apiUrl:window.location.href.substr(0,window.location.href.lastIndexOf('/')+1)+'api/',
mainnetExplorerUrl: "https://msrchain.net/",
testnetExplorerUrl: "http,tnet.msrchain.net/",
testnetExplorerUrl: "http://testnet.msrchain.net/",
testnet: false,
coinUnitPlaces: 12,
txMinConfirms: 10, // corresponds to CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE in Monero
txCoinbaseMinConfirms: 60, // corresponds to CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW in Monero
coinSymbol: 'MSR',
openAliasPrefix: "msr",
coinName: 'Masari',
coinUriPrefix: 'masari:',
addressPrefix: 28,
integratedAddressPrefix: 29,
addressPrefixTestnet: 33,
Expand All @@ -19,12 +15,15 @@ global.config = {
subAddressPrefixTestnet: 73,
feePerKB: new JSBigInt('400000000'),//20^10 - for testnet its not used, as fee is dynamic.
dustThreshold: new JSBigInt('1000000000'),//10^10 used for choosing outputs/change - we decompose all the way down if the receiver wants now regardless of threshold
txChargeRatio: 0.5,
defaultMixin: 4, // minimum mixin for hardfork v5
txChargeAddress: '',
defaultMixin: 12, // default value mixin

idleTimeout: 30,
idleWarningDuration: 20,
maxBlockNumber: 500000000,

coinSymbol: 'MSR',
openAliasPrefix: "msr",
coinName: 'Masari',
coinUriPrefix: 'masari:',
avgBlockTime: 120,
debugMode: false,
maxBlockNumber: 500000000,
};
6 changes: 2 additions & 4 deletions src/d/config.d.ts
@@ -1,5 +1,5 @@
declare var config : {
apiUrl: string,
apiUrl:string,
mainnetExplorerUrl: string,
testnetExplorerUrl: string,
testnet: boolean,
Expand All @@ -18,12 +18,10 @@ declare var config : {
subAddressPrefixTestnet: number,
feePerKB: any,
dustThreshold: any,
txChargeRatio: any,
defaultMixin: any, // minimum mixin for hardfork v5
defaultMixin: number, // default mixin
txChargeAddress: string,
idleTimeout: number,
idleWarningDuration: number,
maxBlockNumber: number,
avgBlockTime: number,
debugMode: boolean,
};
3 changes: 3 additions & 0 deletions src/d/native.d.ts
@@ -0,0 +1,3 @@
interface Window {
native:boolean;
}
7 changes: 3 additions & 4 deletions src/index.html
Expand Up @@ -61,7 +61,7 @@
<a href="#!donate" ><span class="icon" ><i class="fa fa-heart" aria-hidden="true"></i></span> {{ $t("menu.donate") }}</a>
<a href="#!disconnect" class="onlyWhenConnected"><span class="icon" ><i class="fa fa-cog" aria-hidden="true"></i></span> {{ $t("menu.disconnect") }}</a>
<a href="#!network" ><span class="icon" ><i class="fa fa-pie-chart" aria-hidden="true"></i></span> {{ $t("menu.network") }}</a>
<a href="#!mining" ><span class="icon" ><i class="fa fa-institution" aria-hidden="true"></i></span> {{ $t("menu.mining") }}</a>
<a href="#!mining" class="hideOnNative" ><span class="icon" ><i class="fa fa-institution" aria-hidden="true"></i></span> {{ $t("menu.mining") }}</a>

<div id="pageLoading" >
<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
Expand All @@ -71,8 +71,8 @@

<div id="page" ></div>

<div class="copyright" id="copyright">
© 2018 www.masariwallet.com
<div id="copyright" v-cloak="">
<div class="hideOnNative">© 2018 www.masariwallet.com</div>
<div class="right" >
<select v-model="language">
<option value="en">English</option>
Expand All @@ -86,7 +86,6 @@
<a href="#!network" >{{ $t("bottom.network") }}</a>
<a href="https://get.masaricoin.com" target="_blank" >{{ $t("bottom.miningPool") }}</a>
<a href="https://github.com/gnock/masari-webwallet" target="_blank">{{ $t("bottom.github") }}</a>
<!--<a href="" >Twitter</a>-->
</div>
</div>

Expand Down
67 changes: 60 additions & 7 deletions src/index.ts
Expand Up @@ -18,12 +18,16 @@ import {Mnemonic} from "./model/Mnemonic";
import {DestructableView} from "./lib/numbersLab/DestructableView";
import {VueClass, VueVar, VueWatched} from "./lib/numbersLab/VueAnnotate";

//========================================================
//bridge for cnUtil with the new mnemonic class
//========================================================
(<any>window).mn_random = Mnemonic.mn_random;
(<any>window).mn_encode = Mnemonic.mn_encode;
(<any>window).mn_decode = Mnemonic.mn_decode;

// Create VueI18n instance with options
//========================================================
//====================Translation code====================
//========================================================
const i18n = new VueI18n({
locale: 'en',
fallbackLocale: 'en',
Expand All @@ -50,7 +54,8 @@ function loadLangTranslation(lang : string) : Promise<void>{
promise = new Promise<{messages?: any, date?: string, number?: string }>(function (resolve, reject) {
$.ajax({
url: './translations/' + lang + '.json'
}).then(function (data: { messages?: any, date?: string, number?: string }) {
}).then(function (data: any) {
if(typeof data === 'string')data = JSON.parse(data);
storedTranslations[lang] = data;
resolve(data);
}).fail(function () {
Expand Down Expand Up @@ -89,6 +94,10 @@ loadLangTranslation(userLang).catch(function () {
loadLangTranslation('en');
});

//========================================================
//====================Generic design======================
//========================================================

@VueClass()
class MenuView extends Vue{
isMenuHidden : boolean = false;
Expand Down Expand Up @@ -143,12 +152,56 @@ class CopyrightView extends Vue{
}
let copyrightView = new CopyrightView('#copyright');

let router = new Router('./','../../');
window.onhashchange = function () {
router.changePageFromHash();
};
//========================================================
//==================Loading the right page================
//========================================================

let isCordovaApp = document.URL.indexOf('http://') === -1
&& document.URL.indexOf('https://') === -1;

let promiseLoadingReady : Promise<void>;

window.native = false;
if(isCordovaApp){
window.native = true;
$('body').addClass('native');

let promiseLoadingReadyResolve : null|Function = null;
let promiseLoadingReadyReject : null|Function = null;
promiseLoadingReady = new Promise<void>(function(resolve, reject){
promiseLoadingReadyResolve = resolve;
promiseLoadingReadyReject = reject;
});
let cordovaJs = document.createElement('script');
cordovaJs.type = 'text/javascript';
cordovaJs.src = 'cordova.js';
document.body.appendChild(cordovaJs);

let timeoutCordovaLoad = setTimeout(function(){
if(promiseLoadingReadyResolve)
promiseLoadingReadyResolve();
}, 10*1000);
document.addEventListener('deviceready', function(){
if(promiseLoadingReadyResolve)
promiseLoadingReadyResolve();
clearInterval(timeoutCordovaLoad);
}, false);

}else
promiseLoadingReady = Promise.resolve();

promiseLoadingReady.then(function(){
let router = new Router('./','../../');
window.onhashchange = function () {
router.changePageFromHash();
};
});

if ('serviceWorker' in navigator) {
//========================================================
//==================Service worker for web================
//========================================================
//only install the service on web platforms and not native
if (!isCordovaApp && 'serviceWorker' in navigator) {
const showRefreshUI = function(registration : any){
console.log(registration);
swal({
Expand Down
4 changes: 2 additions & 2 deletions src/model/TransactionsExplorer.ts
Expand Up @@ -426,7 +426,8 @@ export class TransactionsExplorer {
wallet: Wallet,
blockchainHeight: number,
obtainMixOutsCallback: (quantity: number) => Promise<any[]>,
confirmCallback: (amount: number, feesAmount: number) => Promise<void>):
confirmCallback: (amount: number, feesAmount: number) => Promise<void>,
mixin : number = config.defaultMixin):
Promise<{ raw: { hash: string, prvKey: string, raw: string }, signed: any }> {
return new Promise<{ raw: { hash: string, prvKey: string, raw: string }, signed: any }>(function (resolve, reject) {
// few multiplayers based on uint64_t wallet2::get_fee_multiplier
Expand All @@ -435,7 +436,6 @@ export class TransactionsExplorer {
let feePerKB = new JSBigInt((<any>window).config.feePerKB);
let priority = default_priority;
let fee_multiplayer = fee_multiplayers[priority - 1];
let mixin = 12;
let neededFee = feePerKB.multiply(13).multiply(fee_multiplayer);
let pid_encrypt = false; //don't encrypt payment ID unless we find an integrated one

Expand Down
3 changes: 1 addition & 2 deletions src/model/blockchain/BlockchainExplorerRpc2.ts
Expand Up @@ -258,8 +258,7 @@ export class WalletWatchdog{
export class BlockchainExplorerRpc2 implements BlockchainExplorer{

// testnet : boolean = true;
serverAddress = window.location.href.substr(0,window.location.href.lastIndexOf('/')+1)+'api/';

serverAddress = config.apiUrl;

heightCache = 0;
heightLastTimeRetrieve = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/importFromFile.html
Expand Up @@ -10,7 +10,7 @@
<div class="body-content" >
<div class="panel">
<div class="body" >
<div class="header-title" >{{ $t("importFromFilePage.importBasePage.title") }}</div>
<div class="header-title" >{{ $t("importFromFilePage.title") }}</div>
<div class="content" >
<div class="field">
<label>{{ $t("importBasePage.parametersBlock.password.label") }}</label>
Expand Down

0 comments on commit b454e8e

Please sign in to comment.