I have implemented expo-IAP in my app and can purchase the subscription. However, there is no way to check subscription status using EXPO. I am hoping to use this react-native-IAP package so I can simply call subscriptionStatus using storekit2 and check the status. That is the only thing I wish to implement.
Is it possible to simply call this so I can get a true/false?
Here is the current implementation I have, and I get undefined when trying to read it.:
import {endConnection,initConnection,IapIosSk2, setup} from "react-native-iap"
async nativeTest() : Promise<any>{
setup({storekitMode:'STOREKIT2_MODE'})
await initConnection()
const status = await (IapIosSk2).subscriptionStatus('sku')
console.log((JSON.stringify(status) + 'status'))
await endConnection();
return status
}
I think they are different depending on where i put 'await' keyword
{"_1":0,"_2":0,"_3":null,"_4":null}
or
undefined
Is there a way to do this without implementing an entire workflow for IAP?
Related
I have an API Gateway resource which calls a Dynamodb post request to query a table. I'm trying to call the API within my React app using Axios. The API is working, returning the data as expected (console log) but I'm getting errors if I try to use #aws-sdk/util-dynamodb (unmarshall) to convert the api data.items response into JSON and use within React.
./node_modules/#aws-sdk/util-dynamodb/dist-es/convertToNative.js 45:14 Module parse failed: Unexpected token (45:14)
Is there a way to use 'unmarshall' within React? Something like this:
useEffect(() => {
const getGoal = async () => {
try {
const response = await api.get(apiUrl)
setGoal(unmarshall(response.data.Items))
This works if I use a Lambda service, but I'm try to see if I can reduce my code.
While I'm not sure on the issue you are getting with unmarshall function, I would suggest using the DynamoDB Document Client which will return your data already unmarshalled.
The DynamoDB Document client simplifies working with items by abstracting the notion of attribute values. This abstraction annotates native JavaScript types supplied as input parameters, and converts annotated response data to native JavaScript types.
I am using express to create my firebase functions, and I understand how to create regular callable functions. I am lost however on the exact way to implement trigger functions for the background (i.e. onCreate, onDelete, onUpdate, onWrite), as well as how Reactjs in the frontend is supposed to receive the data.
The scenario I have is a generic chat system that uses react, firebase functions with express and realtime database. I am generally confused on the process of using triggers for when someone sends a message, to update another user's frontend data.
I have had a hard time finding a tutorial or documentation on the combination of these questions. Any links or a basic programmatic examples of the life cycle would be wonderful.
The parts I do understand is the way to write a trigger function:
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
.onWrite((change, context) => {
// Only edit data when it is first created.
if (change.before.exists()) {
return null;
}
// Exit when the data is deleted.
if (!change.after.exists()) {
return null;
}
// Grab the current value of what was written to the Realtime Database.
const original = change.after.val();
console.log('Uppercasing', context.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return change.after.ref.parent.child('uppercase').set(uppercase);
});
But I don't understand how this is being called or how the data from this reaches frontend code.
Background functions cannot return anything to client. They run after a certain event i.e. onWrite() in this case. If you want to update data at /messages/{pushId}/original to other users then you'll have to use Firebase Client SDK to listen to that path:
import { getDatabase, ref, onValue} from "firebase/database";
const db = getDatabase();
const msgRef = ref(db, `/messages/${pushId}/original`);
onValue(msgRef, (snapshot) => {
const data = snapshot.val();
console.log(data)
});
You can also listen to /messages/${pushId} with onChildAdded() to get notified about any new node under that path.
I am currently working on a project that requires using rtk query. Is there a way to get unwrapped value by default for mutations.
const [removeStudent] = useRemoveStudentMutation()
and i have the call for removeStudent() within try catch because removeStudent can fail in which case i show an error message. Something like this.
try{
await removeStudent().unwrap()
// logic for showing success message
}
catch(e){
//logic for showing error message
}
problem is if i don't use unwarp i'm getting a success message even when the removeStudent() failed. Is there a way i could make unwrap() apply to all mutations.So that i don't have to use unwrap every time i write a mutation.Maybe at createApi level
Thanks
state={locg:''}
componentDidMount(){
fetch('https://maps.googleapis.com/maps/api/geocode/json?address=TajMehal&key=xxxx').then(
response=>response.json()).then
(json=>this.setState({locg:json}));
console.log('Locations from Google wdw',this.state.locg)
}
I need to create array of latitude and longitude.But for above code itself not working for hardcoded area.locg is null
The reason why you are not seeing the result on the console is because the fetch method is asynchronous. Meaning, your console log gets executed first even though it is at the end because the fetch method takes more time to finish. And since it is asynchronous, console log does not have to wait for the fetch to finish executing.
So to address this, you must use async/await. The word async before a function means one simple thing: a function always returns a promise. And the keyword await makes JavaScript wait until that promise (fetch method) settles and returns its result. This is how it should look like:
async componentDidMount() {
await fetch('https://maps.googleapis.com/maps/api/geocode/json?address=TajMehal&key=YOUR_API_KEY')
.then(response=>response.json())
.then(json=>{
this.setState({locg:json});
console.log('Locations from Google wdw',this.state.locg);
});
console.log(this.state.locg)
}
Here is a working sample for your reference: https://stackblitz.com/edit/react-async-await-63982740
I am developing a user search feature in my react/redux application using react-bootstrap-typehead: http://ericgio.github.io/react-bootstrap-typeahead/
The user search calls an API to search the list of users, so I am using the AsyncTypeahead component.
Since I are using Redux, I am storing the loading and search results within the store, so my code looks something like this:
const { searchPeople, loading, searchResults, selectedPerson } = this.props;
<AsyncTypeahead
isLoading={loading}
options={searchResults}
labelKey="DisplayName"
clearButton
minLength={5}
onSearch={searchPeople}
onChange={handleChange}
placeholder="Search for a user..."
renderMenuItemChildren={option => (
<TypeaheadItem key={option.EmployeeID} item={option} {...this.props} />
)}
/>
The onSearch={searchPeople} calls an action in Redux to call the API and store the results in "searchResults":
const searchPeople = term => async dispatch => {
dispatch({
type: REQUEST_SENT
});
const results = await dispatch(applicationActions.peopleSearch(term));
dispatch({
type: REQUEST_RECEIVED,
data: results
});
};
My "peopleSearch" function is stored in another action where I have all of our user search functionality. That is why I am dispatching to another action.
const peopleSearch = searchTerm => async () => {
const url = `https://api-personSearch.test.com/search=${searchTerm}&Output=JSONP`;
const response = await fetchJsonp(url);
const data = await response.json();
return data.slice(0, 10);
};
Everything works perfectly if I search for a user typing slowly. The problem is, if I type a users name quickly or at a normal pace, multiple "REQUEST_SENT" dispatches get called before any "REQUEST_RECEIVED" get called. So looking at the Redux Dev Tools shows results looking like this:
REQUEST_SENT
REQUEST_SENT
REQUEST_SENT
REQUEST_RECEIVED
REQUEST_RECEIVED
REQUEST_RECEIVED
What ends up getting sent to the interface does not end up being the results for the last letter the user ended up typing.
What would be the proper way to use AsyncTypeahead with Redux so that the results are returned in the proper order that they are sent?
Not Great Solution
One thing that ended up working (even though I think it's sort of a hack) is adding a "delay" to the AsyncTypehead. Adding a delay={1000} prop to the AsyncTypeahead component gives the api just enough time to finish it's call before another call to the api is made.
I would like to find a better solution if one is possible.
I'm having a different issue in my usage, but I can suggest a solution to the ordering problem.
Store the last query string in Redux.
When a request completes, ignore it if it isn't for the last query string.
Ideally, you'd cancel the previous request when receiving a new one in onSearch(), but this will have the same effect. If the user keeps typing, delaying long enough for onSearch() to be fired but quick enough to cause overlapping requests, only the last request will display results.
I think it's a bug in the component where AsyncContainer and TypeheadContainer get out of sync. The delay approach works most of the time but even then I could type it in a way that I would get no results. Not happy with this answer either but turning off the cache is the only way to guarantee that doesn't happen.
useCache={false}