Skip to content

Commit b50490b

Browse files
committed
caching
1 parent 920a626 commit b50490b

File tree

9 files changed

+43
-3
lines changed

9 files changed

+43
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"node-notifier": "^5.3.0",
6464
"scrypt-async": "^2.0.1",
6565
"socket.io": "^2.1.1",
66+
"tweetnacl": "^1.0.1",
6667
"vue-markdown": "^2.2.4"
6768
},
6869
"devDependencies": {

src/plugins/PluginRepository.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ class PluginRepositorySingleton {
4949
return acc;
5050
}, {})
5151
}
52+
53+
bustCaches(){
54+
this.signatureProviders().map(sp => {
55+
sp.bustCache();
56+
})
57+
}
5258
}
5359

5460
const PluginRepository = new PluginRepositorySingleton();

src/plugins/defaults/eos.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ const EXPLORER = {
161161
export default class EOS extends Plugin {
162162

163163
constructor(){ super(Blockchains.EOSIO, PluginTypes.BLOCKCHAIN_SUPPORT) }
164+
165+
bustCache(){ cachedInstances = {}; }
164166
defaultExplorer(){ return EXPLORER; }
165167
accountFormatter(account){ return `${account.name}@${account.authority}` }
166168
returnableAccount(account){ return { name:account.name, authority:account.authority, publicKey:account.publicKey, blockchain:Blockchains.EOSIO }}
@@ -209,6 +211,7 @@ export default class EOS extends Plugin {
209211
const network = account.network();
210212
const eos = Eos({httpEndpoint:network.fullhost(), chainId:network.chainId, signProvider});
211213

214+
212215
const perms = Object.keys(keys).map(permission => {
213216
if(!keys[permission].length) return;
214217

@@ -245,7 +248,8 @@ export default class EOS extends Plugin {
245248
}
246249
}).filter(x => !!x);
247250

248-
const options = {authorization:[`${account.name}@owner`]};
251+
const hasOwner = (keys.hasOwnProperty('owner') && keys.owner.length) || account.authorities().map(x => x.authority).includes('owner');
252+
const options = {authorization:[`${account.name}@${hasOwner?'owner':'active'}`]};
249253
return eos.transaction(tr => perms.map(perm => tr.updateauth(perm, options)))
250254
.catch(res => {
251255
popupError(res);

src/plugins/defaults/eth.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import BigNumber from "bignumber.js";
2424
import TokenService from "../../services/TokenService";
2525
import {localizedState} from "../../localization/locales";
2626
import LANG_KEYS from "../../localization/keys";
27+
import nacl from 'tweetnacl'
2728
const erc20abi = require('../../data/abis/erc20');
2829

2930
const web3util = new Web3();
@@ -67,6 +68,8 @@ const EXPLORER = {
6768
export default class ETH extends Plugin {
6869

6970
constructor(){ super(Blockchains.ETH, PluginTypes.BLOCKCHAIN_SUPPORT) }
71+
72+
bustCache(){ cachedInstances = {}; }
7073
defaultExplorer(){ return EXPLORER; }
7174
accountFormatter(account){ return `${account.publicKey}` }
7275
returnableAccount(account){ return { address:account.publicKey, blockchain:Blockchains.ETH }}
@@ -213,13 +216,20 @@ export default class ETH extends Plugin {
213216
if(account && KeyPairService.isHardware(publicKey))
214217
return await HardwareService.sign(account, transaction);
215218

219+
const loom = transaction.hasOwnProperty('loom') && !!transaction.loom;
216220
if(transaction.hasOwnProperty('transaction')) transaction = transaction.transaction;
217221

218222
const basePrivateKey = await KeyPairService.publicToPrivate(publicKey);
219223
if(!basePrivateKey) return;
220224

221-
const privateKey = ethUtil.addHexPrefix(basePrivateKey);
225+
226+
if(loom){
227+
const sigMsg = nacl.sign(transaction, basePrivateKey);
228+
return sigMsg.slice(0, nacl.sign.signatureLength);
229+
}
230+
222231
const tx = new EthTx(transaction);
232+
const privateKey = ethUtil.addHexPrefix(basePrivateKey);
223233
tx.sign(ethUtil.toBuffer(privateKey));
224234
return ethUtil.addHexPrefix(tx.serialize().toString('hex'));
225235
}

src/plugins/defaults/trx.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const EXPLORER = {
4040
export default class TRX extends Plugin {
4141

4242
constructor(){ super(Blockchains.TRX, PluginTypes.BLOCKCHAIN_SUPPORT) }
43+
44+
bustCache(){ cachedInstances = {}; }
4345
defaultExplorer(){ return EXPLORER; }
4446
accountFormatter(account){ return `${account.publicKey}` }
4547
returnableAccount(account){ return { address:account.publicKey, blockchain:Blockchains.TRX }}

src/services/ApiService.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ export default class ApiService {
518518
if(store.state.scatter.settings.networks.find(x => x.fromOrigin === request.payload.origin && x.createdAt > (+new Date() - ((3600 * 12)*1000))))
519519
return resolve({id:request.id, result:new Error("network_timeout", "You can only add 1 network every 12 hours.")});
520520

521+
// All applications can only add 5 networks every 12 hours.
522+
if(store.state.scatter.settings.networks.filter(x => x.createdAt > (+new Date() - ((3600 * 12)*1000))) > 5)
523+
return resolve({id:request.id, result:new Error("network_timeout", "Too many networks were added over the past 12 hours")});
524+
521525
network.fromOrigin = request.payload.origin;
522526
const scatter = store.state.scatter.clone();
523527
scatter.settings.networks.push(network);
@@ -552,6 +556,10 @@ export default class ApiService {
552556
if(store.state.scatter.settings.tokens.filter(x => x.fromOrigin === request.payload.origin && x.createdAt > (+new Date() - ((3600 * 12)*1000))).length > 5)
553557
return resolve({id:request.id, result:new Error("token_timeout", "You can only add up to 5 tokens every 12 hours.")});
554558

559+
// All applications can only add 15 tokens every 12 hours.
560+
if(store.state.scatter.settings.tokens.filter(x => x.createdAt > (+new Date() - ((3600 * 12)*1000))).length > 15)
561+
return resolve({id:request.id, result:new Error("token_timeout", "Too many tokens were added over the past 12 hours.")});
562+
555563
const exists = await TokenService.hasToken(token);
556564
if(exists) return resolve({id:request.id, result:new Error("token_exists", "The user already has this token in their Scatter.")});
557565

src/services/NetworkService.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {Popup} from '../models/popups/Popup'
77
import BalanceService from "./BalanceService";
88
import {localizedState} from "../localization/locales";
99
import LANG_KEYS from "../localization/keys";
10+
import PluginRepository from "../plugins/PluginRepository";
1011

1112

1213
export default class NetworkService {
@@ -37,13 +38,15 @@ export default class NetworkService {
3738
await AccountService.importAllAccountsForNetwork(network);
3839
BalanceService.loadAllBalances(true);
3940
PopupService.push(Popup.snackbar(localizedState(NETWORK.Saved), "check"));
41+
PluginRepository.bustCaches();
4042
return true;
4143
}
4244

4345
static async removeNetwork(network){
4446
return new Promise(resolve => {
4547
PopupService.push(Popup.prompt("Deleting Network", "This will delete this network, as well as all associated accounts and their permissions.", async accepted => {
4648
if(accepted) {
49+
PluginRepository.bustCaches();
4750
const scatter = store.state.scatter.clone();
4851

4952
// Removing accounts and permissions for this network
@@ -64,6 +67,7 @@ export default class NetworkService {
6467
scatter.settings.updateOrPushNetwork(network);
6568
await store.dispatch(Actions.SET_SCATTER, scatter);
6669
PopupService.push(Popup.snackbar(localizedState(LANG_KEYS.SNACKBARS.NETWORK.Saved), "check"));
70+
PluginRepository.bustCaches();
6771
}
6872

6973
}

src/styles/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ html, body {
2222
}
2323

2424
*, *::after, *::before {
25-
-webkit-user-select: none;
25+
//-webkit-user-select: none;
2626
-webkit-user-drag: none;
2727
-webkit-app-region: no-drag;
2828
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9741,6 +9741,11 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0:
97419741
version "0.14.5"
97429742
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
97439743

9744+
tweetnacl@^1.0.1:
9745+
version "1.0.1"
9746+
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.1.tgz#2594d42da73cd036bd0d2a54683dd35a6b55ca17"
9747+
integrity sha512-kcoMoKTPYnoeS50tzoqjPY3Uv9axeuuFAZY9M/9zFnhoVvRfxz9K29IMPD7jGmt2c8SW7i3gT9WqDl2+nV7p4A==
9748+
97449749
type-check@~0.3.2:
97459750
version "0.3.2"
97469751
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72"

0 commit comments

Comments
 (0)