Skip to content

Commit

Permalink
fix: add default Koios api token to prevent CORS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianbormann committed Mar 11, 2024
1 parent b4c51e8 commit effe997
Show file tree
Hide file tree
Showing 8 changed files with 2,825 additions and 2,371 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-preprod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
echo 'VITE_PREPROD_URL=https://preprod.walkinwallet.com' >> .env
echo 'VITE_PREVIEW_URL=https://preview.walkinwallet.com' >> .env
echo 'VITE_MAINNET_URL=https://walkinwallet.com' >> .env
echo 'VITE_KOIOS_API_TOKEN=${{ secrets.KOIOS_API_TOKEN }}' >> .env
- name: 🔥 Edit firebase.json
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
echo 'VITE_PREPROD_URL=https://preprod.walkinwallet.com' >> .env
echo 'VITE_PREVIEW_URL=https://preview.walkinwallet.com' >> .env
echo 'VITE_MAINNET_URL=https://walkinwallet.com' >> .env
echo 'VITE_KOIOS_API_TOKEN=${{ secrets.KOIOS_API_TOKEN }}' >> .env
- name: 🔥 Edit firebase.json
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
echo 'VITE_PREPROD_URL=https://preprod.walkinwallet.com' >> .env
echo 'VITE_PREVIEW_URL=https://preview.walkinwallet.com' >> .env
echo 'VITE_MAINNET_URL=https://walkinwallet.com' >> .env
echo 'VITE_KOIOS_API_TOKEN=${{ secrets.KOIOS_API_TOKEN }}' >> .env
- name: 🔨 Download dependencies and build hosting
run: npm ci && npm run build
Expand Down
5,162 changes: 2,795 additions & 2,367 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"dependencies": {
"@babylonjs/core": "^6.15.0",
"@babylonjs/loaders": "^6.15.0",
"@cardano-foundation/cardano-connect-with-wallet": "^0.2.7",
"@cardano-foundation/cardano-connect-with-wallet-core": "^0.2.3",
"@cardano-foundation/cardano-connect-with-wallet": "^0.2.8",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@fontsource/roboto": "^5.0.8",
Expand Down
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
loadPaintings,
} from './global/api';
import { FAQ, Welcome, Benefits } from './pages';
import { Picture, Room, RoomElement } from './global/types';
import { NftDetailResponse, Picture, Room, RoomElement } from './global/types';

const Main = () => {
const [progress, setProgress] = useState(0);
Expand All @@ -48,7 +48,7 @@ const Main = () => {
stakeAddress = await getStakeAddressFromAdaHandle(address);
}

let nftDetailResponse = [];
let nftDetailResponse: NftDetailResponse = [];

if (stakeAddress.startsWith('stake')) {
nftDetailResponse = await getNFTsFromStakeAddress(stakeAddress);
Expand Down
16 changes: 16 additions & 0 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ const Header = (props: HeaderProps) => {
}
primaryColor={theme.palette.primary.main}
borderRadius={4}
onConnectError={(walletname, error) => {
if (error.name === 'WrongNetworkTypeError') {
setSnackbarVariant('error');
setSnackbarMessage(
`Please make sure that you selected the ${currentNetwork} network in your ${walletname} settings.`
);
setOpen(true);
} else {
console.warn(error);
setSnackbarVariant('error');
setSnackbarMessage(
`Failed to connect to ${walletname}. Please make sure that you created an account in your wallet app on the ${currentNetwork} network.`
);
setOpen(true);
}
}}
customCSS={`
padding-top: 8px;
button {
Expand Down
8 changes: 8 additions & 0 deletions src/global/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { setupCache, buildWebStorage } from 'axios-cache-interceptor';

const MAX_IPFS_FETCH_RETRIES = 20;
const currentNetwork = import.meta.env.VITE_NETWORK || 'mainnet';
const koiosApiToken = import.meta.env.VITE_KOIOS_API_TOKEN || '';
let koiosBaseUrl = 'https://api.koios.rest/api/v0/';

if (currentNetwork === 'preprod') {
Expand All @@ -26,6 +27,13 @@ const axios = setupCache(Axios.create(), {

const defaultAxios = Axios.create();

if (koiosApiToken) {
axios.defaults.headers.common['Authorization'] = `Bearer ${koiosApiToken}`;
defaultAxios.defaults.headers.common[
'Authorization'
] = `Bearer ${koiosApiToken}`;
}

export const getStakeAddressFromPaymentAddress = async (
paymentAddress: string
) => {
Expand Down

0 comments on commit effe997

Please sign in to comment.