Skip to content

Commit

Permalink
Wallet: Bug fixes for 3.2 (#4689)
Browse files Browse the repository at this point in the history
* wip: fix express install path

* chmod and cleanup

* Include keys in zip

* Add genesis env var and remove express path

* Fix cp command in makefile

* Disable submit buttons while forms are loading

* Display errors in send modal

* Remove block rewards & fix empty hostname onboarding bug

* Fix mac ci

* dumb

* feedback

* Fixes

* Fix makefile last time

* fix tests

* Fix account deletion bug and empty block rewards bug

* Hack for "leave password blank"-hint on sandbox

* feedback

* revert Time changes

* update link

Co-authored-by: Brandon Kase <[email protected]>
  • Loading branch information
figitaki and bkase authored Apr 20, 2020
1 parent ea8beb6 commit bb6681e
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 127 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ macos-portable:
@rm -rf _build/coda-daemon-macos/
@rm -rf _build/coda-daemon-macos.zip
@./scripts/macos-portable.sh _build/default/src/app/cli/src/coda.exe src/app/libp2p_helper/result/bin/libp2p_helper _build/coda-daemon-macos
@zip -r -j _build/coda-daemon-macos.zip _build/coda-daemon-macos/
@cp -a package/keys/. _build/coda-daemon-macos/keys/
@cd _build/coda-daemon-macos && zip -r ../coda-daemon-macos.zip .
@echo Find coda-daemon-macos.zip inside _build/

update-graphql:
Expand Down
12 changes: 12 additions & 0 deletions frontend/wallet/src/common/Bindings.re
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ module Fs = {

[@bs.val] [@bs.module "fs"]
external watchFile: (string, unit => unit) => unit = "watchFile";

[@bs.val] [@bs.module "fs"]
external chmodSync: (string, int) => unit = "chmodSync";

[@bs.val] [@bs.module "fs"]
external symlinkSync: (string, string) => unit = "symLinkSync";

[@bs.val] [@bs.module "fs"]
external readdirSync: (string) => array(string) = "readdirSync";

[@bs.val] [@bs.module "fs"]
external renameSync: (string, string) => unit = "renameSync";
};

module Fetch = {
Expand Down
9 changes: 5 additions & 4 deletions frontend/wallet/src/common/CurrencyFormatter.re
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ let rec pow = a =>
}
);
};
let precision_exp = Int64.of_int(pow(10, precision));
let precisionExp = Int64.of_int(pow(10, precision));
let maxFormattedLength = 9;
let toFormattedString = amount => {
if (amount < Int64.zero) {
failwith("CurrencyFormatter.toFormattedString: negative currency input");
Expand All @@ -26,13 +27,13 @@ let toFormattedString = amount => {
} else {
(num_stripped_zeros, num);
};
let whole = Int64.div(amount, precision_exp);
let remainder = Int64.to_int(Int64.rem(amount, precision_exp));
let whole = Int64.div(amount, precisionExp);
let remainder = Int64.to_int(Int64.rem(amount, precisionExp));
if (remainder == 0) {
Int64.to_string(whole);
} else {
let (num_stripped_zeros, num) = go(0, remainder);
Printf.sprintf(
Printf.sprintf(
"%s.%0*d",
Int64.to_string(whole),
precision - num_stripped_zeros,
Expand Down
4 changes: 4 additions & 0 deletions frontend/wallet/src/main/DaemonProcess.re
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ let codaCommand = (~port, ~extraArgs) => {
let env = ChildProcess.Process.env;
let path = Js.Dict.get(env, "PATH") |> Option.with_default(~default="");
let installPath = getPath("userData") ++ del ++ "coda";
// NOTE: This is a workaround for keys that's very specific to unix based systems
let keysPath = "/usr/local/var/coda/keys";
Js.Dict.set(env, "PATH", path ++ del ++ installPath);
Js.Dict.set(env, "CODA_LIBP2P_HELPER_PATH", installPath ++ del ++ "libp2p-helper");
{
Expand All @@ -29,6 +31,8 @@ let codaCommand = (~port, ~extraArgs) => {
"daemon",
"-rest-port",
Js.Int.toString(port),
"-genesis-ledger-dir",
keysPath,
"-config-directory",
ProjectRoot.userData ^/ "coda-config",
|],
Expand Down
73 changes: 46 additions & 27 deletions frontend/wallet/src/render/DownloadLogic.re
Original file line number Diff line number Diff line change
Expand Up @@ -101,58 +101,77 @@ let rec download = (filename, url, encoding, maxRedirects, chunkCb, doneCb) => {
doneCb(Belt.Result.Error("Too many redirects."));
}
| 200 => handleResponse(response, filename, encoding, chunkCb, doneCb)
| _ => doneCb(Belt.Result.Error("Unable to download the daemon."))
| status =>
doneCb(
Belt.Result.Error(
"Unable to download the daemon. Status: " ++ string_of_int(status),
),
)
}
);
Https.Request.onError(request, e => doneCb(Error(e)));
};

// TODO: Make this an env var
let codaRepo = "https://s3-us-west-2.amazonaws.com/wallet.o1test.net/daemon/";
let codaRepo = "https://wallet-daemon.s3-us-west-1.amazonaws.com/";

[@bs.module "electron"] [@bs.scope ("remote", "app")]
external getPath: string => string = "getPath";

let extractZip = (src, dest, doneCb, errorCb) => {
let extractZip = (src, dest, doneCb) => {
let extractArgs = {"path": dest};

let _ =
Bindings.Stream.Readable.create(src)
->(Bindings.Stream.Readable.pipe(Unzipper.extract(extractArgs)))
->Bindings.Stream.Writable.onFinish(doneCb)
->Bindings.Stream.Writable.onError(errorCb);
->Bindings.Stream.Writable.onFinish(() => doneCb(Belt.Result.Ok()))
->Bindings.Stream.Writable.onError(err =>
doneCb(
Belt.Result.Error(
"Error while unzipping the daemon bundle: "
++ (
Js.Exn.message(err)
|> Tc.Option.withDefault(~default="an unknown error occured.")
),
),
)
);

();
};

/**
Unique helper to download and unzip a coda daemon executable.
*/
let installCoda = (tempPath, doneCb) => {
let installPath = getPath("userData") ++ "/coda";
let keysPath = "/usr/local/var/coda/keys/";
let rec moveKeys = files =>
switch (files) {
| [] => ()
| [hd, ...rest] =>
Bindings.Fs.renameSync(installPath ++ "/keys/" ++ hd, keysPath ++ hd);
moveKeys(rest);
};
extractZip(tempPath, installPath, res =>
switch (res) {
| Belt.Result.Ok () =>
Bindings.Fs.chmodSync(installPath ++ "/coda.exe", 0o755);
Bindings.Fs.chmodSync(installPath ++ "/libp2p_helper", 0o755);
Bindings.Fs.readdirSync(installPath ++ "/keys")
|> Array.to_list
|> moveKeys;
doneCb(res);
| Belt.Result.Error(_) => doneCb(res)
}
);
();
};

let downloadCoda = (version, chunkCb, doneCb) => {
let filename = "coda-daemon-" ++ version ++ ".zip";
let tempPath = getPath("temp") ++ "/" ++ filename;
let installPath = getPath("userData") ++ "/coda";
download(tempPath, codaRepo ++ filename, "binary", 1, chunkCb, res =>
switch (res) {
| Belt.Result.Error(_) => doneCb(res)
| _ =>
extractZip(
tempPath,
installPath,
() => doneCb(Belt.Result.Ok()),
err => {
doneCb(
Belt.Result.Error(
"Error while unzipping the daemon bundle: "
++ Tc.Option.withDefault(
~default="an unknown error occured.",
Js.Exn.message(err),
),
),
)
},
);
();
| _ => installCoda(tempPath, doneCb)
}
);
};
50 changes: 32 additions & 18 deletions frontend/wallet/src/render/components/AddressPill.re
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,34 @@ let make = (~pubkey) => {
let isActive = activeAccount === Some(pubkey);

let (hovered, setHovered) = React.useState(() => false);
let (editing, setEditing) = React.useState(() => false);
let (editing, setEditing) = React.useState(() => None);

let pillMode =
switch (hovered, editing, isActive) {
| (false, false, true) => Pill.Blue
| (false, false, false) => Pill.Grey
| (false, None, true) => Pill.Blue
| (false, None, false) => Pill.Grey
| (true, _, _)
| (_, true, _) => Pill.DarkBlue
| (_, Some(_), _) => Pill.DarkBlue
};

let handleEnter = e => {
switch (ReactEvent.Keyboard.which(e)) {
| 13 =>
setEditing(_ => false);
updateAddressBook(
AddressBook.set(
~key=pubkey,
~name=ReactEvent.Keyboard.target(e)##value,
),
);
setEditing(_ => None);
setHovered(_ => false);
| _ => ()
};
};

let handleNameChange = e =>
updateAddressBook(
AddressBook.set(~key=pubkey, ~name=ReactEvent.Form.target(e)##value),
AddressBook.set(~key=pubkey, ~name=ReactEvent.Focus.target(e)##value),
);

let handleClipboard = _ =>
Expand All @@ -113,31 +119,39 @@ let make = (~pubkey) => {
</span>
</Pill>
{switch (hovered, editing) {
| (true, false) =>
| (true, None) =>
<div className=Styles.hoverContainer>
<span className=Styles.copyButton onClick=handleClipboard>
{React.string("Copy")}
</span>
<span
onClick={_ => setEditing(_ => true)} className=Styles.editButton>
onClick={_ =>
setEditing(_ =>
Some(
AddressBook.lookup(addressBook, pubkey)
|> Option.withDefault(~default=""),
)
)
}
className=Styles.editButton>
{React.string("Edit")}
</span>
</div>
| (_, true) =>
<div className=Styles.editing>
| (_, Some(tmpValue)) =>
<form className=Styles.editing>
<input
className=Styles.nameInput
autoFocus=true
onKeyPress=handleEnter
onBlur={_ => setEditing(_ => false)}
onChange=handleNameChange
value={
AddressBook.lookup(addressBook, pubkey)
|> Option.withDefault(~default="")
}
onBlur=handleNameChange
onChange={e => {
let value = ReactEvent.Form.target(e)##value;
setEditing(_ => Some(value));
}}
value=tmpValue
/>
</div>
| (false, false) => React.string("")
</form>
| (false, None) => React.string("")
}}
</div>;
};
3 changes: 2 additions & 1 deletion frontend/wallet/src/render/components/Downloader.re
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ let make = (~onFinish, ~finished, ~error) => {
updateState(((downloaded, total, _)) =>
(downloaded, total, true)
)
| Error(_) => onFinish(result)
| Error(_) =>
onFinish(result)
}
},
)
Expand Down
3 changes: 1 addition & 2 deletions frontend/wallet/src/render/components/Header.re
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ let make = () => {
<div className=Styles.logo onClick={_ => ReasonReact.Router.push("/")}>
<img src=codaSvg alt="Coda logo" />
</div>
<DefaultToast />
<div className=Styles.rightButtons>
<SyncStatusQuery fetchPolicy="no-cache" partialRefetch=true>
{response =>
Expand All @@ -250,4 +249,4 @@ let make = () => {
</a>
</div>
</header>;
};
};
53 changes: 38 additions & 15 deletions frontend/wallet/src/render/views/footer/SendModal.re
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module SendForm = {
open ModalState.Unvalidated;

[@react.component]
let make = (~onSubmit, ~onClose) => {
let make = (~onSubmit, ~onClose, ~loading, ~error) => {
let activeAccount = Hooks.useActiveAccount();
let (addressBook, _) = React.useContext(AddressBookProvider.context);
let (sendState, setModalState) =
Expand All @@ -127,14 +127,16 @@ module SendForm = {
)
};
}}>
{switch (errorOpt) {
| None => React.null
| Some(err) => <Alert kind=`Danger defaultMessage=err />
{switch (error, errorOpt) {
| (None, None) => React.null
| (Some(err), _)
| (_, Some(err)) => <Alert kind=`Danger defaultMessage=err />
}}
spacer
// Disable dropdown, only show active Account
<TextField
label="From"
mono=true
value={AccountName.getName(
Option.getExn(fromStr) |> PublicKey.ofStringExn,
addressBook,
Expand Down Expand Up @@ -187,9 +189,19 @@ module SendForm = {
<Spacer height=1.0 />
//Disable Modal button if no active wallet
<div className=Css.(style([display(`flex)]))>
<Button label="Cancel" style=Button.Gray onClick={_ => onClose()} />
<Button
disabled=loading
label="Cancel"
style=Button.Gray
onClick={_ => onClose()}
/>
<Spacer width=1. />
<Button label="Send" style=Button.Green type_="submit" />
<Button
disabled=loading
label="Send"
style=Button.Green
type_="submit"
/>
</div>
</form>;
};
Expand All @@ -199,22 +211,33 @@ module SendForm = {
let make = (~onClose) => {
<Modal title="Send Coda" onRequestClose={_ => onClose()}>
<SendPaymentMutation>
{(mutation, _) =>
{(mutation, {result}) =>
<SendForm
onClose
loading={result === Loading}
error={
switch (result) {
| Error(err) => Some(err.message)
| _ => None
}
}
onSubmit={(
{from, to_, amountFormatted, feeFormatted, memoOpt}: ModalState.Validated.t,
afterSubmit,
) => {
let variables =
SendPayment.make(
~from=Apollo.Encoders.publicKey(from),
~to_=Apollo.Encoders.publicKey(to_),
~amount=Apollo.Encoders.currency(amountFormatted),
~fee=Apollo.Encoders.currency(feeFormatted),
~memo=?memoOpt,
(),
)##variables;
Js.Dict.fromList([
("from", Apollo.Encoders.publicKey(from)),
("to_", Apollo.Encoders.publicKey(to_)),
("amount", Apollo.Encoders.currency(amountFormatted)),
("fee", Apollo.Encoders.currency(feeFormatted)),
(
"memo",
Tc.Option.map(~f=Js.Json.string, memoOpt)
->Tc.Option.withDefault(~default=Js.Json.null),
),
])
|> Js.Json.object_;
let performMutation =
Task.liftPromise(() =>
mutation(~variables, ~refetchQueries=[|"transactions"|], ())
Expand Down
2 changes: 1 addition & 1 deletion frontend/wallet/src/render/views/onboarding/CustomSetup.re
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let make = (~prevStep, ~completeSetup) => {
icon=Icon.Docs
style=Button.OffWhite
onClick={_ =>
openExternal("https://codaprotocol.com/docs/getting-started/")
openExternal("https://codaprotocol.com/docs/developers/sandbox-node")
}
/>
<Spacer height=2.5 />
Expand Down
Loading

0 comments on commit bb6681e

Please sign in to comment.