Skip to content

Commit 61aa246

Browse files
Fix UI issues
1 parent c4d687d commit 61aa246

File tree

7 files changed

+84
-156
lines changed

7 files changed

+84
-156
lines changed

android/.idea/misc.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "com.filefilego.wallet"
77
minSdkVersion rootProject.ext.minSdkVersion
88
targetSdkVersion rootProject.ext.targetSdkVersion
9-
versionCode 1
10-
versionName "1.0"
9+
versionCode 3
10+
versionName '1.0.2'
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
aaptOptions {
1313
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.

package-lock.json

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mobile-wallet",
33
"private": true,
4-
"version": "0.0.1",
4+
"version": "0.0.2",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
@@ -31,6 +31,7 @@
3131
"aes-es": "^3.0.0",
3232
"aes-js": "^3.1.2",
3333
"axios": "^1.3.6",
34+
"bignumber.js": "^2.3.0",
3435
"bn.js": "^5.2.1",
3536
"crypto-js": "^4.1.1",
3637
"ionicons": "^7.0.0",

src/unit.js

Lines changed: 38 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,56 @@
1-
import BN from "bn.js";
2-
import numberToBN from "number-to-bn";
1+
import BigNumber from 'bignumber.js';
32

4-
const negative1 = new BN(-1);
5-
const zero = new BN(0);
3+
var Units = {}
64

7-
const unitMap = {
8-
FFGZero: "0",
9-
FFGOne: "1",
10-
KFFG: "1000",
11-
MFFG: "1000000",
12-
GFFG: "1000000000",
13-
MicroFFG: "1000000000000",
14-
MiliFFG: "1000000000000000",
15-
FFG: "1000000000000000000",
16-
ZFFG: "1000000000000000000000",
17-
};
5+
var rawUnits = {
6+
ffgzero: "0",
7+
ffgone: "1",
8+
kffg: "1000",
9+
mffg: "1000000",
10+
gffg: "1000000000",
11+
microffg: "1000000000000",
12+
miliffg: "1000000000000000",
13+
ffg: "1000000000000000000",
14+
zffg: "1000000000000000000000",
15+
};
1816

19-
function getValueOfUnit(unitInput) {
20-
const unit = unitInput ? unitInput : "FFG";
21-
var unitValue = unitMap[unit]; // eslint-disable-line
17+
var units = {}
2218

23-
if (typeof unitValue !== "string") {
24-
throw new Error(
25-
`the unit provided ${unitInput} doesn't exists, please use the one of the following units ${JSON.stringify(
26-
unitMap,
27-
null,
28-
2
29-
)}`
30-
);
31-
}
32-
33-
return new BN(unitValue, 10);
34-
}
35-
36-
function numberToString(arg) {
37-
if (typeof arg === "string") {
38-
if (!arg.match(/^-?[0-9.]+$/)) {
39-
throw new Error(
40-
`while converting number to string, invalid number value '${arg}'`
41-
);
42-
}
43-
return arg;
44-
} else if (typeof arg === "number") {
45-
return String(arg);
46-
} else if (
47-
typeof arg === "object" &&
48-
arg.toString &&
49-
(arg.toTwos || arg.dividedToIntegerBy)
50-
) {
51-
if (arg.toPrecision) {
52-
return String(arg.toPrecision());
53-
} else {
54-
return arg.toString(10);
55-
}
56-
}
57-
throw new Error(
58-
`while converting number to string, invalid number value '${arg}' type ${typeof arg}.`
59-
);
60-
}
61-
62-
function fromFFGOne(ffgOneInput, unit, optionsInput) {
63-
var ffgOne = numberToBN(ffgOneInput);
64-
var negative = ffgOne.lt(zero);
65-
const base = getValueOfUnit(unit);
66-
const baseLength = unitMap[unit].length - 1 || 1;
67-
const options = optionsInput || {};
19+
Object.keys(rawUnits).map(function (unit) {
20+
unit = unit.toLowerCase()
21+
units[unit] = new BigNumber(rawUnits[unit], 10)
22+
})
6823

69-
if (negative) {
70-
ffgOne = ffgOne.mul(negative1);
71-
}
24+
Units.units = rawUnits
7225

73-
var fraction = ffgOne.mod(base).toString(10);
26+
var re = RegExp(/^[0-9]+\.?[0-9]*$/)
7427

75-
while (fraction.length < baseLength) {
76-
fraction = `0${fraction}`;
28+
Units.convert = function (value, from, to) {
29+
if (!re.test(value)) {
30+
throw new Error('Unsupported value')
7731
}
7832

79-
if (!options.pad) {
80-
fraction = fraction.match(/^([0-9]*[1-9]|0)(0*)/)[1];
33+
from = from.toLowerCase()
34+
if (!units[from]) {
35+
throw new Error('Unsupported input unit')
8136
}
8237

83-
var whole = ffgOne.div(base).toString(10);
84-
85-
if (options.commify) {
86-
whole = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
38+
to = to.toLowerCase()
39+
if (!units[to]) {
40+
throw new Error('Unsupported output unit')
8741
}
8842

89-
var value = `${whole}${fraction == "0" ? "" : `.${fraction}`}`;
90-
91-
if (negative) {
92-
value = `-${value}`;
93-
}
94-
95-
return value;
43+
return new BigNumber(value, 10).mul(units[from]).round(0, BigNumber.ROUND_DOWN).div(units[to]).toString(10)
9644
}
9745

98-
function toFFGOne(ffgInput, unit) {
99-
var ffg = numberToString(ffgInput); // eslint-disable-line
100-
const base = getValueOfUnit(unit);
101-
const baseLength = unitMap[unit].length - 1 || 1;
102-
103-
// Is it negative?
104-
var negative = ffg.substring(0, 1) === "-"; // eslint-disable-line
105-
if (negative) {
106-
ffg = ffg.substring(1);
107-
}
108-
109-
if (ffg === ".") {
110-
throw new Error(
111-
`while converting number ${ffgInput} to ffgOne, invalid value`
112-
);
113-
}
114-
115-
// Split it into a whole and fractional part
116-
var comps = ffg.split("."); // eslint-disable-line
117-
if (comps.length > 2) {
118-
throw new Error(
119-
`while converting number ${ffgInput} to ffgOne, too many decimal points`
120-
);
121-
}
122-
123-
var whole = comps[0],
124-
fraction = comps[1]; // eslint-disable-line
125-
126-
if (!whole) {
127-
whole = "0";
128-
}
129-
if (!fraction) {
130-
fraction = "0";
131-
}
132-
if (fraction.length > baseLength) {
133-
throw new Error(
134-
`while converting number ${ffgInput} to ffgOne, too many decimal places`
135-
);
136-
}
137-
138-
while (fraction.length < baseLength) {
139-
fraction += "0";
46+
Units.lazyConvert = function (value, to) {
47+
var tmp = value.split(' ')
48+
if (tmp.length !== 2) {
49+
throw new Error('Invalid input')
14050
}
141-
142-
whole = new BN(whole);
143-
fraction = new BN(fraction);
144-
let ffgOne = whole.mul(base).add(fraction); // eslint-disable-line
145-
146-
if (negative) {
147-
ffgOne = ffgOne.mul(negative1);
148-
}
149-
150-
return new BN(ffgOne.toString(10), 10);
51+
return Units.convert(tmp[0], tmp[1], to) + ' ' + to
15152
}
15253

153-
export default {
154-
fromFFGOne,
155-
toFFGOne,
156-
};
54+
export {
55+
Units
56+
}

src/views/CreateKey.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export default {
119119
},
120120
data() {
121121
return {
122+
keySaved: false,
122123
generatingKey: false,
123124
isOpen: false,
124125
confirm1: false,
@@ -171,21 +172,28 @@ export default {
171172
let jsonKey = JSON.parse(fileContents);
172173
let fileName = this.generateFilename(jsonKey.address);
173174
const resultWrite = await Filesystem.writeFile({
174-
path: "filefilegowalletkey.json",
175+
path: "filefilegowalletkey_"+ jsonKey.address + "_" +Math.floor(Date.now() / 1000) + ".json",
175176
data: fileContents,
176177
directory: Directory.Documents,
177178
encoding: Encoding.UTF8,
178179
});
179180
181+
this.keySaved = true;
180182
this.presentAlert("Success", "Your wallet key was saved in: "+ resultWrite.uri);
183+
181184
} catch (e) {
182185
this.presentAlert("Error", "There might be already a wallet key stored, please delete manually if you want to create a new wallet key. Error: "+ e.message);
183186
}
184187
},
185188
goToUnlock() {
189+
if(!this.keySaved) {
190+
this.presentAlert("Error", "Please click on Save wallet key and allow the application to write your key on your device.");
191+
return;
192+
}
193+
186194
if(!this.confirmed) {
187195
this.isOpen = false;
188-
this.$router.push("/unlock")
196+
this.$router.replace("/unlock")
189197
}
190198
},
191199
openFileSelector() {

0 commit comments

Comments
 (0)