-
@@ -146,6 +149,8 @@ class AdminLTEPage extends React.Component {
_this.activeItemById('Wallet')
+ _this.setDefaultServers()
+
await _this.updateState()
setTimeout(() => {
_this.dropDownBalance()
@@ -306,6 +311,37 @@ class AdminLTEPage extends React.Component {
)
}
+
+ // Define backends servers configuration by default
+ setDefaultServers () {
+ try {
+ const walletInfo = _this.props.walletInfo
+ const accessLocation = window.location.hostname
+ console.log('accessLocation', accessLocation)
+
+ // return if servers configurations exist
+ if (walletInfo.selectedServer) return null
+
+ const server1 = 'https://api.fullstack.cash/v3/'
+ const server2 = 'https://free-api.fullstack.cash/v3/'
+
+ const servers = [server1, server2]
+
+ let selectedServer = server1
+ // Assign the second server if the url path
+ // is different of 'wallet.fullstack.cash'
+ if (accessLocation !== 'wallet.fullstack.cash') {
+ selectedServer = server2
+ }
+
+ walletInfo.selectedServer = selectedServer
+ walletInfo.servers = servers
+
+ _this.props.setWalletInfo(walletInfo)
+ } catch (error) {
+ console.warn(error)
+ }
+ }
}
// Props prvided by redux
AdminLTEPage.propTypes = {
diff --git a/src/components/admin-lte/wallet/create.js b/src/components/admin-lte/wallet/create.js
index 275d109..18d459e 100644
--- a/src/components/admin-lte/wallet/create.js
+++ b/src/components/admin-lte/wallet/create.js
@@ -9,7 +9,9 @@ class NewWallet extends React.Component {
constructor (props) {
super(props)
_this = this
- this.state = {}
+ this.state = {
+ inFetch: false
+ }
_this.BchWallet = BchWallet
}
@@ -20,7 +22,10 @@ class NewWallet extends React.Component {
-
+
@@ -60,12 +65,23 @@ class NewWallet extends React.Component {
* it will get overwritten
*/
}
-
+ _this.setState({
+ inFetch: true
+ })
const bchWalletLib = new _this.BchWallet()
const apiToken = currentWallet.JWT
+ const restURL = currentWallet.selectedServer
- if (apiToken) {
- bchWalletLib.bchjs = new bchWalletLib.BCHJS({ apiToken: apiToken })
+ if (apiToken || restURL) {
+ const bchjsOptions = {}
+ if (apiToken) {
+ bchjsOptions.apiToken = apiToken
+ }
+ if (restURL) {
+ bchjsOptions.restURL = restURL
+ }
+ console.log('bchjs options : ', bchjsOptions)
+ bchWalletLib.bchjs = new bchWalletLib.BCHJS(bchjsOptions)
}
await bchWalletLib.walletInfoPromise // Wait for wallet to be created.
@@ -73,14 +89,23 @@ class NewWallet extends React.Component {
const walletInfo = bchWalletLib.walletInfo
walletInfo.from = 'created'
+ Object.assign(currentWallet, walletInfo)
+
const myBalance = await bchWalletLib.getBalance()
// Update redux state
- _this.props.setWalletInfo(walletInfo)
+ _this.props.setWalletInfo(currentWallet)
_this.props.updateBalance(myBalance)
_this.props.setBchWallet(bchWalletLib)
+
+ _this.setState({
+ inFetch: false
+ })
} catch (error) {
console.error(error)
+ _this.setState({
+ inFetch: false
+ })
}
}
}
diff --git a/src/components/admin-lte/wallet/import.js b/src/components/admin-lte/wallet/import.js
index 6b18401..7cb8ab2 100644
--- a/src/components/admin-lte/wallet/import.js
+++ b/src/components/admin-lte/wallet/import.js
@@ -16,7 +16,9 @@ class ImportWallet extends React.Component {
this.state = {
mnemonic: '',
privateKey: '',
- errMsg: ''
+ errMsg: '',
+ inFetch: false
+
}
_this.BchWallet = BchWallet
}
@@ -26,7 +28,10 @@ class ImportWallet extends React.Component {
-
+
@@ -112,32 +117,49 @@ class ImportWallet extends React.Component {
* and it will get overwritten
*/
}
+ _this.setState({
+ inFetch: true
+ })
const bchWalletLib = new _this.BchWallet(_this.state.mnemonic)
const apiToken = currentWallet.JWT
+ const restURL = currentWallet.selectedServer
- if (apiToken) {
- bchWalletLib.bchjs = new bchWalletLib.BCHJS({ apiToken: apiToken })
+ if (apiToken || restURL) {
+ const bchjsOptions = {}
+ if (apiToken) {
+ bchjsOptions.apiToken = apiToken
+ }
+ if (restURL) {
+ bchjsOptions.restURL = restURL
+ }
+ console.log('bchjs options : ', bchjsOptions)
+ bchWalletLib.bchjs = new bchWalletLib.BCHJS(bchjsOptions)
}
-
await bchWalletLib.walletInfoPromise // Wait for wallet to be created.
const walletInfo = bchWalletLib.walletInfo
walletInfo.from = 'imported'
+ Object.assign(currentWallet, walletInfo)
+
const myBalance = await bchWalletLib.getBalance()
// Update redux state
- _this.props.setWalletInfo(walletInfo)
+ _this.props.setWalletInfo(currentWallet)
_this.props.updateBalance(myBalance)
_this.props.setBchWallet(bchWalletLib)
// Reset form and component state
_this.resetValues()
+ _this.setState({
+ inFetch: false
+ })
} catch (error) {
console.warn(error)
_this.setState({
- errMsg: error.message
+ errMsg: error.message,
+ inFetch: false
})
}
}
diff --git a/src/redux/createStore.js b/src/redux/createStore.js
index ec8a046..a498c67 100644
--- a/src/redux/createStore.js
+++ b/src/redux/createStore.js
@@ -41,28 +41,37 @@ const reducer = (state, action) => {
}
// Wallet info from local storage
-const localWallet = getWalletInfo()
+const localStorageInfo = getWalletInfo()
// Creates an instance of minimal-slp-wallet, with
// the local storage information if it exists
const instanceWallet = () => {
try {
- if (!localWallet.mnemonic) return null
+ if (!localStorageInfo.mnemonic) return null
- const bchWalletLib = new BchWallet(localWallet.mnemonic)
+ const bchWalletLib = new BchWallet(localStorageInfo.mnemonic)
+
+ const jwtToken = localStorageInfo.JWT
+ const restURL = localStorageInfo.selectedServer
+ const bchjsOptions = {}
- const jwtToken = localWallet.JWT
if (jwtToken) {
- bchWalletLib.bchjs = new bchWalletLib.BCHJS({ apiToken: jwtToken })
+ bchjsOptions.apiToken = jwtToken
}
+ if (restURL) {
+ bchjsOptions.restURL = restURL
+ }
+ bchWalletLib.bchjs = new bchWalletLib.BCHJS(bchjsOptions)
+
return bchWalletLib
} catch (error) {
console.warn(error)
}
}
+
// initial state
const initialState = {
- walletInfo: localWallet.mnemonic ? localWallet : {}, // Object wallet info
+ walletInfo: localStorageInfo, // Object wallet info
bchBalance: 0, // Wallet Balance
bchWallet: instanceWallet() // minimal-slp-wallet instance
}