forked from cardstack/snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmixins.ts
57 lines (53 loc) · 1.6 KB
/
mixins.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { mapState } from 'vuex';
import numeral from 'numeral';
import prettyMs from 'pretty-ms';
import networks from '@snapshot-labs/snapshot.js/src/networks.json';
import domains from '@snapshot-labs/snapshot-spaces/spaces/domains.json';
import store from '@/store';
import { shorten } from '@/helpers/utils';
const domainName = window.location.hostname;
let env = 'master';
if (domainName.includes('localhost')) env = 'local';
if (domainName === 'demo.snapshot.org' || domainName === 'demo.snapshot.page')
env = 'develop';
// @ts-ignore
const modules = Object.entries(store.state).map(module => module[0]);
export default {
data() {
return {
env
};
},
computed: {
...mapState(modules),
domain() {
return domains[domainName];
}
},
methods: {
_ms(number) {
const diff = number * 1e3 - new Date().getTime();
return prettyMs(diff);
},
_n(number, format = '(0.[00]a)') {
return numeral(number).format(format);
},
_shorten(str: string, key: any): string {
if (!str) return str;
let limit;
if (typeof key === 'number') limit = key;
if (key === 'symbol') limit = 6;
if (key === 'name') limit = 64;
if (key === 'choice') limit = 12;
if (limit)
return str.length > limit ? `${str.slice(0, limit).trim()}...` : str;
return shorten(str);
},
_ipfsUrl(ipfsHash: string): string {
return `https://${process.env.VUE_APP_IPFS_GATEWAY}/ipfs/${ipfsHash}`;
},
_explorer(network, str: string, type = 'address'): string {
return `${networks[network].explorer}/${type}/${str}`;
}
}
};