Nexusoft / NexusInterface

The official Logical and Interface layers of the Nexus Software Stack.
https://crypto.nexus.io/wallet
MIT License
32 stars 12 forks source link

sendNXS error #175

Closed SwapzoneIO closed 2 years ago

SwapzoneIO commented 2 years ago

There is an error in the sendNXS function - the transmitted parameters are lost and no pop-up window appears to confirm sending. If we follow the instruction, nothing happens.

We could use Send function, but it changes the core code not the module. Could you please help to resolve this issue?

Qrysto commented 2 years ago

Do you mean the sendNXS function on modules?

Qrysto commented 2 years ago

And which branch are you on?

SwapzoneIO commented 2 years ago
  1. Yes
  2. https://gitlab.com/swapzone/nexus-wallet-integration (you mean it?)
SwapzoneIO commented 2 years ago

And we have an API key in the code, and the module code is in the public domain, but this is not safe. Could you please tell us how the security issue is usually solved?

Qrysto commented 2 years ago
  1. https://gitlab.com/swapzone/nexus-wallet-integration (you mean it?)

I mean which branch of NexusInterface, if you're running Nexus Wallet from the code, or are you just using the official release (v3.0.6)?

Regarding the API key security, I don't know the details about how exactly your module would works and what issue you have, so I can't recommend a solution. But generally speaking, a Nexus Wallet Module works just like a normal website frontend, so in most cases, you should treat your module security the same way as with a normal website.

SwapzoneIO commented 2 years ago

We tried both. We ran Nexus Wallet from the code and used the official release. 


In the first case, the function opened a window, but did not pass the address and amount parameters to this window. In the second case, the window did not open and we changed the code of the wallet itself a little to see the result of the program.

Qrysto commented 2 years ago

I guess the reason why the parameters are not populated into form fields is that you didn't pass a third parameter to sendNXS which should be a boolean flag indicating you're sending in Tritium mode (if a truthy value is passed) or Legacy mode (if a falsy value is passed). So most likely you'd want to pass true for the third parameter. I know that this is not a good API design, but it's old code and a lot has changed in the latest code, including this sendNXS function, it's just not yet officially released.

I'm still not sure why it doesn't open the Send screen for you in some cases. I tested both cases, the official released wallet and also ran from the code, and the Send screen does open for me in both cases (even when I'm logged out or in Legacy mode).

Qrysto commented 2 years ago

@SwapzoneIO What parameters did you pass to sendNXS when it failed to open the Send screen?

SwapzoneIO commented 2 years ago

@Qrysto We send a request to api.swapzone.io Request address: /v1/exchange/create, it returns a response to us, the data from which we use as parameters of the sendNXS function The parameters themselves: 1 argument: [response.data.transaction.addressDeposit, fromAmount] - 1 element is the data from the request response (described above), and the second is the amount of sent tokens (we want to send) 2nd argument: 'message' If (suddenly) it's wrong, is there any documentation on this function? Can we see the source of this function? To understand how to work with it

Qrysto commented 2 years ago

@SwapzoneIO Here's the sendNXS function in the preload script https://github.com/Nexusoft/NexusInterface/blob/master/src/module_preload.js#L67

which will invoke the 'send-nxs' event on the main wallet https://github.com/Nexusoft/NexusInterface/blob/master/src/shared/lib/modules/webview.js#L153

Your 1st argument might be the problem. It should be an array of objects, where each object contains information about one recipient (you can send to multiple recipients at once). Each object should look like this:

{
  address: ...,
  amount: ...,
}
vianormonroes commented 2 years ago

@Qrysto I am developer of swapzoneIO. Thank you! the source code of sendNXS function helped us to solve our problem. However we have several questions about implementation of the sendNXS function.

-https://github.com/Nexusoft/NexusInterface/blob/e8919463c2715ed6fe6d00011b9ff6e732ea257a/src/shared/lib/modules/webview.js#L193

Why sendFrom field is null here? We want to provide address of wallet we send nxs from.

-https://github.com/Nexusoft/NexusInterface/blob/e8919463c2715ed6fe6d00011b9ff6e732ea257a/src/shared/lib/modules/webview.js#L197

Why fiatAmount field is empty string here? We would also like to provide this value.

Is it possible to provide sendFrom and fiatAmount data to the built-in Send NXS page by using sendNXS function?

Qrysto commented 2 years ago

Why sendFrom field is null here? We want to provide address of wallet we send nxs from.

Nexus Wallet Module 3.0.x didn't support sendFrom on sendNXS. The reason was that I thought it's up to each user to decide which account they want to send from, because how each person manage their funds might be different. Nevertheless, the next wallet version will allow modules to specify this sendFrom field if they want. In the end, for a programming interface, it's better to start strict then open up to allow more options later than the opposite, which would creates more breaking changes. The new changes are already available on the Merging branch https://github.com/Nexusoft/NexusInterface/tree/Merging/docs/Modules (might not be final).

Why fiatAmount field is empty string here? We would also like to provide this value.

fiatAmount should be automatically calculated based when the amount field is changed (I'll make automatic when a module calls sendNXS too). If modules feed data into that field, there're chances that they will use a different price data source than the wallet, leading to a different number, or worse, they can totally show a wrong number to fool users. So I'd prefer fiatAmount being 100% automatically calculated by the wallet for consistency and safety.

Qrysto commented 2 years ago

Thank you! the source code of sendNXS function helped us to solve our problem.

I'll close this since the main issue is already resolved. Thank you for letting me know! Feel free to ask more questions even when the issue is closed