Skip to content

Commit

Permalink
add logic to check if xlm address is exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
schnogz committed May 2, 2019
1 parent e862169 commit a8ac55d
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 12 deletions.
39 changes: 38 additions & 1 deletion config/mocks/wallet-options-v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,48 @@
"coinCode": "XLM",
"coinTicker": "XLM",
"colorCode": "xlm",
"displayName": "Stellar",
"config": {
"network": "public",
"sendTimeOutSeconds": 10
},
"displayName": "Stellar",
"exchangeAddresses": [
"GA4BYMUO5D7OLGVJWZ2D5FCWU7SB63FNZ4QUU574SMNA6ELK5TZD3SO3",
"GA5XIGA5C7QTPTWXQHY6MCJRMTRZDOSHR6EFIBNDQTCQHG262N4GGKTM",
"GABSZVZBYEO5F4V5LZKV7GR4SAJ5IKJGGOF43BIN42FNDUG7QPH6IMRQ",
"GAHK7EEG2WWHVKDNT4CEQFZGKF2LGDSW2IVM4S5DP42RBW3K6BTODB4A",
"GAW4E6NGM4NPNX2LO2BKDPCCTUX3FJLKWHPU4VQPGBIBQGD6JTVF5C7C",
"GAWPTHY6233GRWZZ7JXDMVXDUDCVQVVQ2SXCSTG3R3CNP5LQPDAHNBKL",
"GB3RMPTL47E4ULVANHBNCXSXM2ZA5JFY5ISDRERPCXNJUDEO73QFZUNK",
"GB6YPGW5JFMMP2QB2USQ33EUWTXVL4ZT5ITUNCY3YKVWOJPP57CANOF3",
"GB7GRJ5DTE3AA2TCVHQS2LAD3D7NFG7YLTOEWEBVRNUUI2Q3TJ5UQIFM",
"GBKTJSNUSR6OCXA5WDWGT33MNSCNQHOBQUBYC7TVS7BOXDKWFNHI4QNH",
"GBOEEVARKVASOQSSXCAHNTGJTVALJE2QM3AQQ2K3VXACQ6JJREQRJZKB",
"GBSTRH4QOTWNSVA6E4HFERETX4ZLSR3CIUBLK7AXYII277PFJC4BBYOG",
"GBSTRUSD7IRX73RQZBL3RQUH6KS3O4NYFY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GKJKOBMS5LOQPHCIADZU5POEF3IICZ7XNQJ65Y6",
"GARAR5QR7WRL24MQMSO4INWV7C5SE4EE2YVXTLD6ORONYFHSUAGZYSLN",
"GCWYV4ZICBNDYJ3HE7GHPF3MJPIH63QNCWYPFTC5BQOIODUEI7HJBJVS",
"GDQP2KPQGKIHYJGXNUIYOMHARUARCA7DJT5FO2FFOOKY3B2WSQHG4W37",
"GBQ6RTEHEHXFPKSWCIM4KSVQXBANLFMVV6FJIZDLTF3ZOGFHTBDZUYDD"
],
"hasLockboxSupport": true,
"icons": {
"default": "xlm-circle-filled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const SECOND_STEP_CANCEL_CLICKED =
'@EVENT.SEND_XLM.SECOND_STEP_CANCEL_CLICKED'
export const FIRST_STEP_TO_TOGGLED = '@EVENT.SEND_XLM.FIRST_STEP_TO_TOGGLED'
export const FIRST_STEP_FEE_TOGGLED = '@EVENT.SEND_XLM.FIRST_STEP_FEE_TOGGLED'

export const SEND_XLM_CHECK_DESTINATION_ACCOUNT_EXISTS =
'@EVENT.SEND_XLM_CHECK_DESTINATION_ACCOUNT_EXISTS'
export const SEND_XLM_CHECK_DESTINATION_ACCOUNT_EXISTS_LOADING =
Expand All @@ -21,6 +22,16 @@ export const SEND_XLM_CHECK_DESTINATION_ACCOUNT_EXISTS_SUCCESS =
'@EVENT.SEND_XLM_CHECK_DESTINATION_ACCOUNT_EXISTS_SUCCESS'
export const SEND_XLM_CHECK_DESTINATION_ACCOUNT_EXISTS_FAILURE =
'@EVENT.SEND_XLM_CHECK_DESTINATION_ACCOUNT_EXISTS_FAILURE'

export const SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE =
'@EVENT.SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE'
export const SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE_LOADING =
'@EVENT.SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE_LOADING'
export const SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE_SUCCESS =
'@EVENT.SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE_SUCCESS'
export const SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE_FAILURE =
'@EVENT.SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE_FAILURE'

export const FIRST_STEP_PRIORITY_FEE_CLICKED =
'@EVENT.SEND_XLM.FIRST_STEP_PRIORITY_FEE_CLICKED'
export const FIRST_STEP_REGULAR_FEE_CLICKED =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ export const sendXlmCheckDestinationAccountExistsFailure = e => ({
type: AT.SEND_XLM_CHECK_DESTINATION_ACCOUNT_EXISTS_FAILURE,
payload: e
})
export const sendXlmCheckIfDestinationIsExchange = address => ({
type: AT.SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE,
payload: address
})
export const sendXlmCheckIfDestinationIsExchangeLoading = () => ({
type: AT.SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE_LOADING
})
export const sendXlmCheckIfDestinationIsExchangeSuccess = isExchange => ({
type: AT.SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE_SUCCESS,
payload: isExchange
})
export const sendXlmCheckIfDestinationIsExchangeFailure = e => ({
type: AT.SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE_FAILURE,
payload: e
})
export const firstStepFeeToggled = () => ({
type: AT.FIRST_STEP_FEE_TOGGLED
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Remote } from 'blockchain-wallet-v4/src'
const INITIAL_STATE = {
step: 1,
checkDestination: Remote.NotAsked,
isDestinationExchange: Remote.NotAsked,
payment: Remote.NotAsked,
feeToggled: false,
showNoAccountForm: false
Expand Down Expand Up @@ -36,6 +37,15 @@ export default (state = INITIAL_STATE, action) => {
case AT.SEND_XLM_CHECK_DESTINATION_ACCOUNT_EXISTS_FAILURE: {
return assoc('checkDestination', Remote.Failure(payload), state)
}
case AT.SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE_LOADING: {
return assoc('isDestinationExchange', Remote.Loading, state)
}
case AT.SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE_SUCCESS: {
return assoc('isDestinationExchange', Remote.Success(payload), state)
}
case AT.SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE_FAILURE: {
return assoc('isDestinationExchange', Remote.Failure(payload), state)
}
case AT.FIRST_STEP_SUBMIT_CLICKED: {
return assoc('step', 2, state)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export default ({ api, coreSagas }) => {
AT.SEND_XLM_CHECK_DESTINATION_ACCOUNT_EXISTS,
sendXlmSagas.checkDestinationAccountExists
)
yield takeLatest(
AT.SEND_XLM_CHECK_IF_DESTINATION_IS_EXCHANGE,
sendXlmSagas.checkIfDestinationIsExchange
)
yield takeLatest(actionTypes.CHANGE, sendXlmSagas.formChanged)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ export default ({ api, coreSagas }) => {
payment = yield payment.to(value)
// Do not block payment update when to is changed w/ destinationAccount check
yield put(A.paymentUpdatedSuccess(payment.value()))
// After updating payment success check if destinationAccount exists
// check if destination exists
yield put(A.sendXlmCheckDestinationAccountExists(value))
// check if destination is an exchange
yield put(A.sendXlmCheckIfDestinationIsExchange(value))
return
case 'amount':
const xlmAmount = prop('coin', payload)
Expand Down Expand Up @@ -120,7 +122,7 @@ export default ({ api, coreSagas }) => {
}
}

const checkAccountExistance = function * (id) {
const checkAccountExistence = function * (id) {
try {
yield call(api.getXlmAccount, id)
return true
Expand All @@ -129,11 +131,24 @@ export default ({ api, coreSagas }) => {
}
}

const checkIfDestinationIsExchange = function * ({ payload }) {
try {
yield put(A.sendXlmCheckIfDestinationIsExchangeLoading())
const exchangeAddresses = (yield select(
selectors.core.walletOptions.getXlmExchangeAddresses
)).getOrElse([])
const isExchange = includes(payload, exchangeAddresses)
yield put(A.sendXlmCheckIfDestinationIsExchangeSuccess(isExchange))
} catch (e) {
yield put(A.sendXlmCheckIfDestinationIsExchangeFailure(e))
}
}

const checkDestinationAccountExists = function * ({ payload }) {
try {
yield put(A.sendXlmCheckDestinationAccountExistsLoading())
const destinationAccountExists = yield call(
checkAccountExistance,
checkAccountExistence,
payload
)

Expand Down Expand Up @@ -310,6 +325,7 @@ export default ({ api, coreSagas }) => {
return {
initialized,
checkDestinationAccountExists,
checkIfDestinationIsExchange,
destroyed,
firstStepSubmitClicked,
maximumAmountClicked,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export const getCheckDestination = path([
'sendXlm',
'checkDestination'
])
export const getIsDestinationExchange = path([
'components',
'sendXlm',
'isDestinationExchange'
])
export const getFeeToggled = path(['components', 'sendXlm', 'feeToggled'])
export const showNoAccountForm = path([
'components',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const getData = createDeepEqualSelector(
[
selectors.components.sendXlm.getPayment,
selectors.components.sendXlm.getCheckDestination,
selectors.components.sendXlm.getIsDestinationExchange,
selectors.core.data.xlm.getTotalBalance,
selectors.core.kvStore.lockbox.getLockboxXlmAccounts,
selectors.core.settings.getCurrency,
Expand All @@ -19,6 +20,7 @@ export const getData = createDeepEqualSelector(
(
paymentR,
checkDestinationR,
isDestinationExchangeR,
balanceR,
lockboxXlmAccountsR,
currencyR,
Expand All @@ -32,6 +34,7 @@ export const getData = createDeepEqualSelector(
'lockbox',
coinAvailabilityR('XLM').getOrElse({})
)
const destinationIsExchange = isDestinationExchangeR.getOrElse(false)
const transform = (payment, currency, rates) => {
const effectiveBalance = propOr('0', 'effectiveBalance', payment)
const reserve = propOr('0', 'reserve', payment)
Expand All @@ -47,18 +50,19 @@ export const getData = createDeepEqualSelector(

return {
activeField,
balanceStatus: balanceR,
currency,
destination,
destinationAccountExists,
effectiveBalance,
destinationIsExchange,
excludeLockbox,
fee,
destination,
isDestinationChecked,
from,
reserve,
currency,
rates,
destinationAccountExists,
balanceStatus: balanceR,
isDestinationChecked,
noAccount,
excludeLockbox
rates,
reserve
}
}
return lift(transform)(paymentR, currencyR, ratesR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const getEthTxFuse = state =>
getSupportedCoins(state).map(path(['ETH', 'lastTxFuse']))
export const getXlmSendTimeOutSeconds = state =>
getSupportedCoins(state).map(path(['XLM', 'config', 'sendTimeOutSeconds']))
export const getXlmExchangeAddresses = state =>
getSupportedCoins(state).map(path(['XLM', 'exchangeAddresses']))
export const getCoinAvailability = curry((state, coin) =>
getSupportedCoins(state).map(path([toUpper(coin), 'availability']))
)
Expand Down

0 comments on commit a8ac55d

Please sign in to comment.