I'm fetching data from an external api. This data is currency pair e.g EURUSD with real time Ask and Bid Prices respectively e.g 1.17123 , 1.17150. The user of the application is therefore required to input a future price such that if the Ask or the Bid price reaches that price inputted by the user, a message is logged. The createAlert function in the code below doesnt output the correct soluion. It Logs the price inputted instead of checking the if-else condition. I think i'm doing it wrongly, kindly assist
function createAlert(pricealert){
let CurrencyPair = {...currency.data.prices[clickedindex].instrument}
let AskPrice = {...currency.data.prices[clickedindex].closeoutAsk}
let BidPrice = {...currency.data.prices[clickedindex].closeoutBid}
if(AskPrice ==pricealert || BidPrice === pricealert)
return Alert.alert
else
console.log("Create alert")
}
<Modal
visible={modalopen}
animationType={"fade"}
>
<View style={styles.modal}>
<View>
<Text style=>
{currency.data.prices[clickedindex].instrument}
</Text>
<Text style=>
{currency.data.prices[clickedindex].closeoutAsk}/{currency.data.prices[clickedindex].closeoutBid}
</Text>
<Card.Divider/>
<View style=>
<View style={styles.inputWrap}>
<TextInput
style={styles.textInputStyle}
value={pricealert}
onChangeText = {(pricealert) => setPricealert(pricealert)}
placeholder="Alert Price"
placeholderTextColor="#60605e"
numeric
keyboardType='decimal-pad'
/>
</View>
<View style={styles.inputWrap}>
</View>
</View>
<TouchableOpacity
onPress={() =>
ActionSheet.show(
{
options: BUTTONS,
cancelButtonIndex: CANCEL_INDEX,
destructiveButtonIndex: DESTRUCTIVE_INDEX,
title: "How do you want to receive your notification"
},
buttonIndex => {
setSheet({ clicked: BUTTONS[buttonIndex] });
}
)}
style={styles.button}
>
<Text>ActionSheet</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button}
onPress={() => {
createAlert(pricealert);
setModalOpen(false);
showToastWithGravityAndOffset();} }
>
<Text style={styles.buttonTitle}>OK</Text>
</TouchableOpacity>
</View>
</View>
</Modal>
Aucun commentaire:
Enregistrer un commentaire