rsksmart / rwallet

The RSK Wallet is based on our rWallet open-source code-base, which will allow developers and organizations to use it to build their own apps.
https://developers.rsk.co/wallet/
GNU General Public License v3.0
43 stars 22 forks source link

Use object-oriented method to achieve coin filter #552

Open chrisli30 opened 4 years ago

chrisli30 commented 4 years ago

From Brendan,

The coin type determination should be achieved using object-oriented method as other property, instead of using a separate configuration array variable.

Example 1: https://github.com/rsksmart/rwallet/commit/955c072e7cec8d1c5adcf4bfa960083027a7fa19#diff-91fb241661b3998d5c42b6029dd03123R45-R49 if (symbol === 'RBTC') { rawTransaction.to = to; rawTransaction.data = memo; } else { const assetContract = ASSETS_CONTRACT[symbol][type];

if (symbol === 'RBTC') should be implemented in coin.createRawTransaction(to, memo) since each coin has the property symbol.

Example 2, in src/pages/wallet/wallet.connect/index.js line 235,

const rskCoins = _.filter(coins, (coin) => coin.symbol !== 'BTC' && coin.type === net);
    if (_.isEmpty(rskCoins)) {
      };          return null;
    }
    return {
      address: Rsk3.utils.toChecksumAddress(rskCoins[0].address, networkId),
      privateKey: rskCoins[0].privateKey,
    };

all lines with _.filter() should be replaced by the actual logic such as coin.getPrivateKey()

chrisli30 commented 4 years ago

@bguiz Please see if this issue is as described in your message.

bguiz commented 4 years ago

The config file should store the category for each "coin", specifically whether it is a native currency of the crypto network (e.g. R-BTC on RSK), or if it is a token (e.g. RIF on RSK`).

Once that is done, instead of deciding how to construct the transaction based on a hard coded value, can use this category value to decide instead. The intent behind this is: