Why Stripe 3ds popup closes automaticly? - javascript

I'm trying to intigrate Stripe 3ds flow to the project. Everything goes ok, but when you do nothing after pop-up appearing for about 5 seconds it closes automaticly.
Here is a part of my code:
const sendServerReq = async (id) {
const { status, {data: payment_intent_secret} } = await purchaseRequest(id);
if (status === 'requires_action' && payment_intent_secret) {
const {
error: errorAction,
paymentIntent
} = await stripe.confirmCardPayment(payment_intent_secret);
if (errorAction) {
onError(errorAction.message);
return;
}
await sendServerReq(paymentIntent.id);
} else {
return onSuccess();
}
}

Related

Why useFocusEffect doesn't notice when the screen is not on focus and comes back to focus

What I want is to notice when the user is on the app screen, or off the application(in the setting screen in this case)
The reason Im doing this is because I want to check the permissions of the user if it's "denied" or "granted".
and if its "denied" to not allow the user to navigate to other screen, and if its "granted" to allow the user to navigate to other screen.
const PermissionsIntro = ({ navigation}) => {
async function configurePushNotifications() {
const { status } = await Notifications.getPermissionsAsync();
let finalStatus = status;
console.log('status of notification', status)
if(status === 'granted'){
setNavigate(true)
}
else if (finalStatus !== 'granted') {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
setNavigate(false)
}
else if (finalStatus !== 'granted') {
setNavigate(false)
Alert.alert('Permission required', 'Push notifications need the appropriate permissions.');
return;
}
const pushTokenData = await Notifications.getExpoPushTokenAsync();
setExpoPushToken(pushTokenData.data);
if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.DEFAULT,
});
}
}
useFocusEffect(
React.useCallback(() => {
configurePushNotifications();
alert('screen is on application')
console.log('tfffffff')
return () => {
openSettings()
console.log('screen is on settings')
// alert('screen is on settings')
};
}, [])
);
const openSettings = () => {
Linking.openSettings();
};
//onPress function
const confirm = () => {
console.log('navigate', navigate);
if (navigate == true) {
navigation.navigate('CreateProfile');
}
else {
console.log('turn the permissions to true!');
openSettings();
}
};
}
When I navigate to this screen it showed me the alert alert(screen is on application),
but when I go to the settings and go back to the application the useFocusEffect is not called at all.
How can I fix this error?
useFocusEffect is not able to run when app is coming to foreground/background unfortunately. In this case you should use AppState instead. AppState can tell you if the app is in the foreground or background, and notify you when the state changes. More can be found in the documentation.

opensea place bid using metamask

const NetworkToUse = process.env.REACT_APP_NETWORK;
const mnemonicWalletSubprovider = new MnemonicWalletSubprovider({
mnemonic: process.env.REACT_APP_MNEMONIC,
});
const infuraRpcSubprovider = new RPCSubprovider({
rpcUrl: `https://${NetworkToUse}.infura.io/v3/${process.env.REACT_APP_INFURA_KEY}`,
});
const providerEngine = new Web3ProviderEngine();
if (window.ethereum) {
providerEngine.addProvider(new SignerSubprovider(window.ethereum));
}
// providerEngine.addProvider(mnemonicWalletSubprovider);
providerEngine.addProvider(infuraRpcSubprovider);
providerEngine.start();
const seaport = new OpenSeaPort(
providerEngine,
{
networkName: NetworkToUse === "mainnet" ? Network.Main : Network.Rinkeby,
apiKey: process.env.REACT_APP_API_KEY,
},
(arg) => {
console.log("From OpenSeaPort CB:");
console.log(arg);
}
);
const placeBidMetaMask = async (order) => {
setIsProcessing(true);
if (typeof window.ethereum === "undefined") {
setError("Please make sure you have MetaMask installed!");
return;
}
if (!bidPrice || bidPrice < asset.price) {
setError("Insufficient Funds!");
return;
}
const { tokenId, tokenAddress } = order.asset;
try {
const [userAccount] = await window.ethereum.request({
method: "eth_requestAccounts",
});
const offer = await seaport.createBuyOrder({
asset: {
tokenId,
tokenAddress,
schemaName: asset.details.assetContract.schemaName,
},
accountAddress: userAccount,
startAmount: bidPrice,
});
console.log(offer);
setMessage("Buy Order Created");
} catch (err) {
setError(err.message);
console.log(err.message);
} finally {
setIsProcessing(false);
}
};
I am using metamask as wellet for bidding
Hi, I am using above code to place bid on opensea It is working but, I am using my personal MNEMONIC
But, in real time i can't get this from users meta mask wallet.
Is there any alternate way to place the bid.
I am using metamask as wellet for bidding
Hi, I am using above code to place bid on opensea It is working but, I am using my personal MNEMONIC
But, in real time i can't get this from users meta mask wallet.
Is there any alternate way to place the bid.

Async Input / Output CLI deno

I'm building a chat program in deno cli. I already wrote the function that gets new messages and prints them on screen every 1 second. While it's doing this it also asynchronously listens to the cli input (using standard deno readLines) so when the user hits enter his message gets posted. However if you happen to be writing a message and the refresh hits before you press enter, the new messages are written right next to what you were writing and you need to type it again.
As you can see, I was typing nonsense (fdghsjkasjdhfv) but Alice said hello again, the refresh function kicked in and wrote the new message right after what I was typing.
The question is: Is there a way to save the typed stuff, clear it and print it back once the refresh function has posted the new messages?
The code I'm using:
import { readLines } from "https://deno.land/std/io/mod.ts";
async function read() {
for await(const line of readLines(Deno.stdin)) {
if (!settings.printing) return line;
}
}
let settings = { exit: false, user: 'anon', lastID: 0, printing: false };
async function main() {
console.log('== DISCUSSION ==========================');
printMessages();
do {
let line = await read();
if (/^!\s*(quit|exit)$/.test(line)) settings.exit = true;
else sendMessage(line);
} while (!exit);
}
await main();
function sendMessage(text) {
postRequest('postMessage', {
user: settings.user, data: text
}).then(response => {
if (response.status != 200) {
console.log('[Connection Error!]');
return;
}
});
}
function printMessages() {
postRequest('getDiscussion', {
id: settings.lastID // get the messages after the lastID received
}).then(response => {
if (response.status != 200) return;
response.json().then(j => {
if (j.length != 0) settings.lastID = j[j.length - 1].id;
settings.printing = true;
for (const m of j) {
const time = new Date(m.time).toTimeString().slice(0, 5);
console.log(
`[${time}][${m.user}]: `,
m.data
);
}
settings.printing = false;
if (!settings.exit) setTimeout(printMessages, 1000);
});
});
}
function postRequest(api, data) {
let form = new FormData();
for (const property in data) {
form.append(property, data[property]);
}
return fetch(`https://example.com/api/${api}.php`, {
method: "POST",
body: form
});
}

WARN Tried to show an alert while not attached to an Activity REACT-NATIVE

Sometimes i get this error, but i really dont know whats causing this or where its come from, this error only appears when i unmount the component:
componentDidMount() {
this.track_changed = TrackPlayer.addEventListener("playback-track-changed", this.play_selected_music);
this.requestPermission();
}
componentWillUnmount() {
this.track_changed.remove();
TrackPlayer.pause().then(() => {
TrackPlayer.destroy();
});
}
when unmount, remove all the listeners then pause and destroy the player, when i open the app again, soooome times it appears and also some times appears and alert showing error: null, but cant find where its coming from, im using some helpers functions to fetch data, but i think therey not the issue:
export const Fetch_options = async () => {
try {
const options = JSON.parse(await AsyncStorage.getItem("options"));
if (options != null) {
return options;
}else {
return false;
}
}catch(error) {
alert("hola" + error);
}
}
export const Fetch_Lycrics = async () => {
try {
const lycrics = JSON.parse(await AsyncStorage.getItem("lycrics"));
if (lycrics != null) {
return lycrics;
}else {
return null;
}
}catch(error) {
alert("hola" + error);
}
}

Attempting to change the state of the error variable by calling the setRegisterError function but when it's called the state of error is not changing

handleSubmit function called in onClick of a button
handleSubmit = async (name) => {
let registerResponse = await registerAPI(this.state)
const resultResponse = await registerResponse.json()
console.log(registerResponse)
console.log(resultResponse)
if (registerResponse.status === 200) {
const userInfo = {
hasura_id: resultResponse.hasura_id,
name: name
}
let setUserResponse = await setUserAPI(userInfo)
const resultResponseSetUser = await setUserResponse.json()
console.log(setUserResponse)
console.log(resultResponseSetUser)
if (setUserResponse["affected_rows"]) {
this.setRegisterError('')
}
else {
this.setRegisterError(resultResponseSetUser.message)
}
}
else {
this.setRegisterError(resultResponse.message)
}
}
setRegisterError function is supposed to change the state of error and if there's no error it's supposed to navigate to a new screen
setRegisterError = error => {
// If there's an error display that, otherwise send to new screen to tell the user to verify email address and then login
this.setState({error})
if(error === '') {
this.props.navigation.navigate('PostRegister')
}
}

Categories