-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wallet native logic #27
Conversation
Check if the result has a code. Code 0 or public async postTx(tx: StdTx): Promise<PostTxResult> {
const result = await this.lcdClient.postTx(tx);
if (!result.txhash.match(/^([0-9A-F][0-9A-F])+$/)) {
throw new Error("Received ill-formatted txhash. Must be non-empty upper-case hex");
}
return result.code !== undefined
? {
height: Uint53.fromString(result.height).toNumber(),
transactionHash: result.txhash,
code: result.code,
rawLog: result.raw_log || "",
}
: {
logs: result.logs ? parseLogs(result.logs) : [],
rawLog: result.raw_log || "",
transactionHash: result.txhash,
data: result.data ? fromHex(result.data) : undefined,
};
} |
Example how to check for errors: try {
const res = await client.sendTokens(rcpt, [{denom: "ushell", amount: "123456"}]);
if (res.code) {
throw new Error(`sendToken error: ${res.log}`);
}
// handle success case
} catch (e) {
// handle error case
} You can do more introspection with the result when |
Reviewed the UI by clicking around. And actually had a hard time to get send to error... validation logic and all. Places to improve:
I do actually get a "nice" error message now: "Send transaction failed:insufficient funds: insufficient account funds; 72994ushell < 74000ushell: failed to execute message" I will take a look at the code, but the flow is working pretty well. Mainly changing |
Also, tried search. It doesn't change anything. I tried the following accounts (which both exist on coralnet):
Please check the search field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good besides my comments
packages/logic/src/config.ts
Outdated
readonly httpUrl: string; | ||
readonly feeToken: string; | ||
readonly gasPrice: number; | ||
readonly httpUrl?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why all optional? Does this make sense if it misses httpUrl
or such fields?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd need to know which ones can be optional, I just needed codeId to be optional at the moment
@@ -0,0 +1,26 @@ | |||
import { useSdk } from "@cosmicdapp/logic"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stuff that can move to design in a future PR, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move ProtectedSwitch to logic, since it does not have to do with layout or styling
getClient() | ||
.sendTokens(recipientAddress, transferAmount) | ||
.then((result) => { | ||
//Rudimentarily check if rawLog is error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for if (result.code) {
here. We can definitely not rely on the "github.com" error message. Soon we will turn off all the stack trace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the source of my confusion was that result is PostTxResult
but it does not give me access to the code field
. I see now that I have 2 type guards: isPostTxSuccess
and isPostTxFailure
, that let me narrow the type. However, I'm guessing that I can just do if (isPostTxFailure(result))
} | ||
|
||
// eslint-disable-next-line react/display-name | ||
const Input = React.forwardRef(( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking for where this was used (to see the search logic) and couldn't find it anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for wasting your time looking for the logic, I was not 100% sure about the flow and so it was not implemented yet. I had thought about pre-filling the searchbar with your own address and letting you change it to check other addresses' balance, but the flow described in #28 looks much better
Please just fix the logic changes and do not worry about the UI stuff I mentioned above. I made another issue to rethink those flows: #28 I think the Native Token and the CW20 Token designs are more different than I thought. And you made some good points when we talked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Propose some improvements to the coin map logic
[key: string]: MappedCoin; | ||
} | ||
|
||
function mapCoin(coin: Coin, coinMap: CoinMap): Coin { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you do here, and in the config and it seems to work.
Seems a bit odd going back and forth and back again.
I would just store a map native token -> display token, and always pass the native token (ushell
) as arguments internally. Then you can just do the forward mapping for the display.
let mappedAmount = "0"; | ||
|
||
if (mappedCoin.fractionalDigits > 0) { | ||
mappedAmount = Decimal.fromAtomics(coin.amount, mappedCoin.fractionalDigits).toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove a few lines above and below and just use this for the forward mapAmount
}; | ||
|
||
const coinMap: CoinMap = { | ||
ushell: { denom: "SHELL", fractionalDigits: 6 }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep ushell
and ureef
and remove the other two. Going back and forth risks loosing precision.
(In fact if this ever ends up as a number, this is only safe if we have positive fractionalDigits)
Closes #7