Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
: props.nationId; // hardcode for bitnation chat group
const selectedNation = resolveNation(props.nations || [], nationIdX);
if (!selectedNation) {
if (Platform.OS === "ios") {
props.navigator.pop();
} else {
props.navigator.dismissModal();
}
return;
}
this.nationId = selectedNation.idInSmartContract;
// Creating the socket-client instance will automatically connect to the server.
this.connection = SocketIOClient(config.CHAT_URL, {
transports: ["websocket"],
upgrade: false,
query: `token=${config.AUTH_TOKEN}`
});
this.connection.on("connect", () => {
this.connection.emit("room:join", {
nation_id: this.nationId,
});
});
this.state = {
messages: [],
joined: false
};
} else {
// add initial bot message
this.state = {
messages: [
{
componentDidMount() {
if (this.props.isBot !== true && this.connection) {
this.props.showSpinner();
// load initial messages
const URL = `${config.CHAT_URL}/messages/${this.nationId}?auth_token=${config.AUTH_TOKEN}`;
fetch(URL)
.then(response => response.json())
.then(
(json) => {
const messages = deprecatedCreateGiftedChatMessageObject(json.reverse());
this.props.hideSpinner();
this.setState(previousState => ({
messages: GiftedChat.append(previousState.messages, messages),
}));
},
() => {
this.props.hideSpinner();
},
);
// add socket listener
componentDidMount() {
// TODO: Does chat migration apply to here as well?
if (this.props.isBot !== true && this.connection) {
this.props.showSpinner();
// load initial messages
const URL = `${config.CHAT_URL}/messages/${this.nationId}?auth_token=${config.AUTH_TOKEN}`;
fetch(URL)
.then(response => response.json())
.then(
(json) => {
const messages = createGiftedChatMessageObject(json.reverse());
this.props.hideSpinner();
this.setState(previousState => ({
messages: GiftedChat.append(previousState.messages, messages),
}));
},
() => {
this.props.hideSpinner();
},
);
// add socket listener
import env from 'react-native-config';
import axios from 'axios';
const api = axios.create({
baseURL: env.API_URL,
headers: {
'Authorization':
`Bearer ${env.AUTH_TOKEN}`,
'Content-Type': 'application/vnd.api+json',
},
});
export default api;