Error: Please pass numbers as strings or BN objects to avoid precision errors - smartcontracts

<tbody>
<tr style={{color: 'white'}}>
<td>{window.web3.utils.fromWei(this.props.stakingBalance, 'ether')} USDT</td>
<td>{window.web3.utils.fromWei(this.props.rwdBalance, 'ether')} RWD</td>
</tr>
</tbody>
Error: Please pass numbers as strings or BN objects to avoid precision errors.
not able to display the stakingBalance and rwdBalance, it asks to pass as strings or BN objects

As the error says "Please pass numbers as strings"
<td>{window.web3.utils.fromWei(String(this.props.stakingBalance), 'ether')} USDT</td>
<td>{window.web3.utils.fromWei(String(this.props.rwdBalance), 'ether')} RWD</td>
If you are getting this balances via await web3.eth.getBalance() function, this function already returns "string". If so, the problem is somewhere in your code, you might have this function:
web3.utils.toWei("passStringValueHere", "ether")

Related

Coldfusion - Need to get string data between opening and closing tags

I am trying to get specific data between two strings which are a opening and closing tag. Normally I would just parse it using XmlParse but the problem is it has a lot of other junk in the dataset.
Here is an example of the large string:
test of data need to parse:<?xml version="1.0" encoding="UTF-8"?><alert xmlns="urn:oasis:names:tc::cap:1.2"><identifier>_2020-12-16T17:32:5620201116173256</identifier><sender>683</sender><sent>2020-12-16T17:32:56-05:00</sent><status>Test</status><msgType>Alert</msgType><source>test of data need to parse</source><scope>Public</scope><addresses/><code>Test1.0</code><note>WENS IPAWS</note><info><language>en-US</language></info>
<capsig:Signature xmlns:capsig="http://www.w3.org/2000/09/xmldsig">
<capsig:Info>
<capsig:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n"/>
<capsig:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-morersa-sha256"/>
<capsig:Referrer URI="">
<capsig:Trans>
<capsig:Trans Algorithm="http://www.w3.org/2000/09/xmldsigenveloped-signature"/>
</capsig:Trans>
<capsig:DMethod Algorithm="http://www.w3.org/2001/04/xmlencsha256"/>
<capsig:DigestValue>wjL4tqltJY7m/4=</capsig:DigestValue>
</capsig:Referrer>
</capsig:Info>
test of data need to parse:<?xml version="1.0" encoding="UTF-8"?><alert xmlns="urn:oasis:names:tc::cap:1.2"><identifier>_2020-12-16T17:32:5620201116173256</identifier><sender>683</sender><sent>2020-12-16T17:32:56-05:00</sent><status>Test</status><msgType>Alert</msgType><source>test of data need to parse</source><scope>Public</scope><addresses/><code>Test1.0</code><note>WENS IPAWS</note><info><language>en-US</language></info>
So what I need to do is just extract the following:
<capsig:Info>
<capsig:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n"/>
<capsig:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-morersa-sha256"/>
<capsig:Referrer URL="">
<capsig:Trans>
<capsig:Trans Algorithm="http://www.w3.org/2000/09/xmldsigenveloped-signature"/>
</capsig:Trans>
<capsig:DMethod Algorithm="http://www.w3.org/2001/04/xmlencsha256"/>
<capsig:DigestValue>wjL4tqltJY7m/4=</capsig:DigestValue>
</capsig:Referrer>
</capsig:Info>
I have searched everywhere and I have found where things can be done with characters and counts but none of them really worked. Tried doing it with SQL but because the constant change in the string it causes issues. So my plan was get everything after "capsig:Info" and before "</capsig:Info>" then insert it into a table.
Is there a way to do this with Coldfusion?
Any suggestions would be appreciated.
Thanks!
Yes, you can use a regular expression match to extract the substring containing the text between the <capsig:Info> ... </capsig:Info> tags by using the ColdFusion function reMatch() which will return an array of all substrings that match the specified pattern. This can be done using the line of code below.
<!--- Use reMatch to extract all pattern matches into an array --->
<cfset parsedXml = reMatch("<capsig:Info>(.*?)</capsig:Info>", xmlToParse)>
<!--- parsedXml is an array of strings. The result will be found in the first array element as such --->
<cfdump var="#parsedXml[1]#" label="parsedXml">
You can see this using the demo here.
https://trycf.com/gist/00be732d93ef49b2427768e18e371527/lucee5?theme=monokai

Convert array to a string inside AutocompleteArrayInput

I'm trying to use parse and format to convert the input from AutocompleteArrayInput before storing the data in my database(postgres with graphql API), but i keep getting a error when the component try to map the input.
AutocompleteArrayInput outputs an array and I need to convert it to a single string so I can store a colection of tags in my database, i know this is not the best solution, but i dont have control over the database.
<AutocompleteArrayInput
parse={v => v.join("-")}
// format={v => v.split("-")}
label="Areas Involved"
source="areas_involved"
validate={required()}
choices={areas_involved_choices}
/>

Using a filter in part of a string

I have a filter that formats a number based on what stat type it is (percent, integer, currency, etc). I want to use this filter on a value as part of a string. See below:
<js-widget
v-on:click="this.selectedReportId = key"
:selected="this.selectedReportId == key"
:icon="report.icon"
:stat="report.current | stat report.statType"
:title="report.title"
:tooltip="report.tooltip"
:percent="report.percent"
:description="'Previous value: '+(report.past | stat report.statType)">
</js-widget>
As you can see in the :stat parameter, I can use the filter if it is the only thing in the expression. But when it tries to evaluate the :description parameter, I get Error when evaluating expression. Is it possible to use a filter in this way?
It's been very long since the question was asked, but if someone searches, I happen to know the solution.
First there is a way to call a filter from inside the vue component. Actually all filters are stored in the
this.$options.filters
collection. So if you want to call a filter from inside the component you should do
...
this.$options.filters.stat(report.past, report.statType)
...
And if you want to do the same from the markup, you should also call filter not like filter (| syntax), but like the component method
<js-widget
v-on:click="this.selectedReportId = key"
:selected="this.selectedReportId == key"
:icon="report.icon"
:stat="report.current | stat report.statType"
:title="report.title"
:tooltip="report.tooltip"
:percent="report.percent"
:description="'Previous value: '+ $options.filters.stat(report.past, report.statType)">
</js-widget>
Or, better, with template string
:description = "`Previous value: ${$options.filters.stat(report.past, report.statType)}`"
The filter is something available outside of the expression you are evaluating – so that's not going to work syntactially
I would use a computed property instead. For more information, see http://vuejs.org/guide/computed.html.

Why am I getting “Too many positionals passed…” in this call to HTTP::Request.new?

I tried six or so variations on this code and excepting hardcoded Strs like GET => … I always got this error. Why? How can I fix it and understand it? Is it a bug in the HTTP::Request code?
Code
#!/usr/bin/env perl6
use HTTP::UserAgent; # Installed today with panda, for HTTP::Request.
HTTP::Request.new( GET => "/this/is/fine" ).WHICH.say;
# First, check that yes, they are there.
say %*ENV<REQUEST_METHOD>, " ", %*ENV<REQUEST_URI>;
# This and single value or slice combination always errors-
HTTP::Request.new( %*ENV<REQUEST_METHOD>, %*ENV<REQUEST_URI> );
Output with invariable error
$ env REQUEST_METHOD=GET REQUEST_URI=/ SOQ.p6
HTTP::Request|140331166709152
GET /
Too many positionals passed; expected 1 argument but got 3
in method new at lib/HTTP/Request.pm6:13
in block <unit> at ./SOQ.p6:11
HTTP::Request is from this package — https://github.com/sergot/http-useragent/ — Thank you!
Try
HTTP::Request.new(|{ %*ENV<REQUEST_METHOD> => %*ENV<REQUEST_URI> });
instead of the more obvious
HTTP::Request.new( %*ENV<REQUEST_METHOD> => %*ENV<REQUEST_URI> );
If the left-hand side of => isn't a literal, we won't bind to a named parameter. Instead, a pair object gets passed as positional argument.
To work around this, we construct an anonymous hash that gets flattened into the argument list via prefix |.
As a bonus, here are some more creative ways to do it:
HTTP::Request.new(|%( %*ENV<REQUEST_METHOD REQUEST_URI> ));
HTTP::Request.new(|[=>] %*ENV<REQUEST_METHOD REQUEST_URI> );

Testing dynamic attributes with cucumber, undefined method

We have a Style model with dynamic attributes, which can be saved by filling one field with the attribute key and the next field with the value.
A typical params hash looks like this:
{"utf8"=>"✓", "style"=>{"collection_id"=>"48", "program_id"=>"989", "number"=>"454632", "name"=>"t67f", "category_id"=>"19", "field_KEY"=>"VALUE"}, "commit"=>"save", "id"=>"4521"}
This works as intended when clicking it through, and the "field_KEY" => "VALUE" pair creates a new dynamic attribute with a getter(field_KEY) and setter(field_KEY=) method.
The Problem is: If the process is simulated with cucumber, something calls the getters for all keys in the hash before the attributes are set, including field_KEY.
Normal attributes will return nil for a new record, but since the getter for field_KEY has not yet been created, this results in an
`UndefinedMethodError: undefined method 'field_KEY'`.
Now my question: would you rather track down the caller of the field_KEY getter and mess around with cucumber, or should I try to simulate a fake method, something like:
def check_method(method_name)
if method_name =~ /^field_/
nil
else
... # let the Error be raised
end
Better ideas or solutions are more than welcome
Thanks
The Problem was:
The call to field_KEY came from pickle, because I included the step
And the style's "field_KEY" should be "VALUE"
which looks like this:
Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}$/) do |name, attribute, expectation, expected|
actual_value = model(name).send(attribute)
expectation = expectation.gsub(' ', '_')
case expected
when 'nil', 'true', 'false'
actual_value.send(expectation, send("be_#{expected}"))
when /^[+-]?[0-9_]+(\.\d+)?$/
actual_value.send(expectation, eql(expected.to_f))
else
actual_value.to_s.send(expectation, eql(eval(expected)))
end
end
I still don't know why the dynamic_attribute getter had not been created up to this point.
What I ended up doing:
In my opinion (also, it solved the problem ;)), cucumber tests should be black-box tests, thats why I chose to change the steps and now I use
And the "key1" field should contain "KEY"
which checks if the field has been filled with the correct value after the page reloads.