Skip to content

Commit 4abe526

Browse files
Merge pull request #1050 from Chia-Network/develop
Release: Version 1.0.20
2 parents 5972fbf + 8bc65e1 commit 4abe526

File tree

5 files changed

+48
-41
lines changed

5 files changed

+48
-41
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "climate-action-data-trust",
3-
"version": "1.0.19",
3+
"version": "1.0.20",
44
"private": true,
55
"author": "Chia Network Inc. <[email protected]>",
66
"homepage": "./",

src/components/blocks/MyAccount.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ const MyAccount = ({ openModal = false, onClose, isHeader = true }) => {
3838
const [serverAddress, setServerAddress] = useState(null);
3939
const [isLogInModalOpen, setIsLogInModalOpen] = useState(openModal);
4040
const appStore = useSelector(state => state.app);
41-
const isUserLoggedIn =
42-
appStore.apiKey !== null && appStore.serverAddress !== null;
41+
const isUserLoggedIn = appStore.serverAddress !== null;
4342
const intl = useIntl();
4443
const dispatch = useDispatch();
4544

4645
const signUserIn = () => {
47-
if (serverAddress && apiKey && validateUrl(serverAddress)) {
46+
if (serverAddress && validateUrl(serverAddress)) {
4847
dispatch(signIn({ apiKey, serverAddress }));
4948
setServerAddress(null);
5049
setApiKey(null);
@@ -124,7 +123,7 @@ const MyAccount = ({ openModal = false, onClose, isHeader = true }) => {
124123
<StyledFieldContainer>
125124
<StyledLabelContainer>
126125
<Body>
127-
*<FormattedMessage id="api-key" />
126+
<FormattedMessage id="api-key" />
128127
</Body>
129128
</StyledLabelContainer>
130129
<InputContainer>
@@ -136,13 +135,6 @@ const MyAccount = ({ openModal = false, onClose, isHeader = true }) => {
136135
placeholderText="xxxxxxx-xxxxxx-xxxxxx"
137136
/>
138137
</InputContainer>
139-
{apiKey === null && (
140-
<Body size="Small" color="red">
141-
{intl.formatMessage({
142-
id: 'add-valid-api-key',
143-
})}
144-
</Body>
145-
)}
146138
</StyledFieldContainer>
147139
</ModalFormContainerStyle>
148140
}

src/store/actions/app.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,18 @@ export const setNotificationMessage = (type, id) => {
128128

129129
export const signIn = ({ apiKey, serverAddress }) => {
130130
return async dispatch => {
131-
if (apiKey && serverAddress) {
132-
localStorage.setItem('apiKey', apiKey);
131+
if (serverAddress) {
133132
localStorage.setItem('serverAddress', serverAddress);
133+
let payload = { serverAddress };
134+
135+
if (apiKey) {
136+
localStorage.setItem('apiKey', apiKey);
137+
payload = { ...payload, apiKey };
138+
}
139+
134140
dispatch({
135141
type: actions.SIGN_USER_IN,
136-
payload: {
137-
apiKey,
138-
serverAddress,
139-
},
142+
payload: payload,
140143
});
141144
dispatch(getOrganizationData());
142145
dispatch(refreshApp(true));
@@ -162,13 +165,17 @@ export const signInFromLocalStorage = () => {
162165
return async dispatch => {
163166
const apiKey = localStorage.getItem('apiKey');
164167
const serverAddress = localStorage.getItem('serverAddress');
165-
if (apiKey && serverAddress) {
168+
169+
if (serverAddress) {
170+
let payload = { serverAddress };
171+
172+
if (apiKey) {
173+
payload = { ...payload, apiKey };
174+
}
175+
166176
dispatch({
167177
type: actions.SIGN_USER_IN,
168-
payload: {
169-
apiKey,
170-
serverAddress,
171-
},
178+
payload: payload,
172179
});
173180
}
174181
};

src/store/actions/climateWarehouseActions.js

+25-17
Original file line numberDiff line numberDiff line change
@@ -2558,30 +2558,38 @@ export const getVintages = options => {
25582558
const fetchWrapper = async (url, payload) => {
25592559
const apiKey = localStorage.getItem('apiKey');
25602560
const serverAddress = localStorage.getItem('serverAddress');
2561-
const doesSignInDataExist = apiKey != null && serverAddress != null;
2562-
2563-
if (doesSignInDataExist) {
2564-
const payloadWithApiKey = { ...payload };
2565-
if (payloadWithApiKey?.headers) {
2566-
payloadWithApiKey.headers = {
2567-
...payloadWithApiKey.headers,
2568-
'x-api-key': apiKey,
2569-
};
2570-
} else {
2571-
payloadWithApiKey.headers = { 'x-api-key': apiKey };
2561+
2562+
// Check if serverAddress is set and is a string; this results in changing the URL to the stored server address
2563+
// and adds the API key header (if applicable).
2564+
if (serverAddress && serverAddress.endsWith) {
2565+
const newPayload = { ...payload };
2566+
2567+
// If API key was set, add the header
2568+
if (apiKey) {
2569+
if (newPayload.headers) {
2570+
// Add to existing headers
2571+
newPayload.headers = {
2572+
...newPayload.headers,
2573+
'x-api-key': apiKey,
2574+
};
2575+
} else {
2576+
// Create headers object if it doesn't exist
2577+
newPayload.headers = { 'x-api-key': apiKey };
2578+
}
25722579
}
25732580

2574-
const serverAddressUrl =
2575-
serverAddress[serverAddress.length - 1] !== '/'
2576-
? `${serverAddress}/`
2577-
: serverAddressUrl;
2581+
//Ensure server address ends in a forward slash
2582+
const addressWithSlash = serverAddress.endsWith('/')
2583+
? serverAddress
2584+
: serverAddress + '/';
25782585

2586+
// Replace original URL with stored server URL (with slash)
25792587
const newUrl = url.replace(
25802588
/(https:|http:|)(^|\/\/)(.*?\/)/g,
2581-
serverAddressUrl,
2589+
addressWithSlash,
25822590
);
25832591

2584-
return fetch(newUrl, payloadWithApiKey);
2592+
return fetch(newUrl, newPayload);
25852593
}
25862594

25872595
return fetch(url, payload);

src/translations/tokens/en-US.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@
321321
"add-project-with-label": "Add a project with a label first",
322322
"sign-out": "Disconnect",
323323
"sign-in": "Connect",
324-
"api-key": "Api key",
324+
"api-key": "API key",
325325
"server-address": "Server address",
326326
"log-in-to-remote-node": "Log in to remote node",
327327
"add-valid-server-address": "Add a valid server address",

0 commit comments

Comments
 (0)