Skip to content

Commit

Permalink
define summoning message to prepare for equip->circles and add error …
Browse files Browse the repository at this point in the history
…handling on api calls with explicit throws for better ui/ux flows
  • Loading branch information
kibagateaux committed Sep 28, 2024
1 parent 045e152 commit e043447
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/inventory/maliks-majik.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ const equip: HoF = async () => {
// if (!isMobile()) just send apply request to server without signWithId NFC interaction
const address = await getStorage<string>(ID_PLAYER_SLOT);
console.log('address to get verified: ', address);
const result = address
? await signWithId(`summon:${address}`)
: await signWithId(`summon:${(await getSpellBook()).address}`);
const summonSign = address
? `summon:${address}`
: `summon:${(await getSpellBook()).address}`;
const result = await signWithId(summonSign);
console.log('summon sign', summonSign, result);

console.log('verified address signature: ', result);
if (!result) throw Error('Majik not found');
Expand Down
23 changes: 21 additions & 2 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
saveStorage,
} from 'utils/config';
import { getSpellBook } from 'utils/zkpid';
import { debug } from './logging';

// TODO persist cache to local storage for better offline use once internet connection lost?
// https://www.apollographql.com/docs/react/caching/advanced-topics#persisting-the-cache
Expand Down Expand Up @@ -66,7 +67,7 @@ export const qu =
console.log('api:qu:vars', variables);
console.log('api:qu:verification ', `'${cleaned}'`, '---', majikMsg);

return query
const response = query
? getGqlClient().query({
...baseRequest,
// fetchPolicy: 'cache-first', // TODO add useCache: boolean to switch between query vs readQuery?
Expand All @@ -81,6 +82,24 @@ export const qu =
${cleaned}
`,
});

if (response.error) {
debug(response.error, {
user: { id: spellbook.address },
tags: {
api: true,
},
extra: {
query,
mutation,
variables,
},
});

throw Error(response.err);
} else {
return response;
}
};

export const QU_GET_PLAYER_CONFIG = `
Expand Down Expand Up @@ -231,7 +250,7 @@ export const getHomeConfig = async (pid?: string): Promise<HomeConfigMap> => {
return {}; // no player. return nil
})
.catch((error) => {
console.error('Home:config:get: ERR ', error);
console.log('Home:config:get: ERR ', error);
return {}; // no player. return nil
});
};
Expand Down
1 change: 1 addition & 0 deletions src/utils/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const getProviderId = async ({ playerId, provider }: obj): Promise<string
id &&
playerId === (await getStorage<string>(ID_PLAYER_SLOT)) &&
(await saveStorage(ID_PROVIDER_IDS_SLOT, { [provider]: id }, true));
// asssume local save always succeeds
return id;
} catch (e) {
console.log('util:oauth:getProviderId:ERROR', e);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/serviceWorkerRegistration.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function registerValidSW(swUrl, config) {
};
})
.catch((error) => {
console.error('Error during service worker registration:', error);
console.log('Error during service worker registration:', error);
});
}

Expand Down Expand Up @@ -137,7 +137,7 @@ export function unregister() {
registration.unregister();
})
.catch((error) => {
console.error(error.message);
console.log(error.message);
});
}
}
2 changes: 1 addition & 1 deletion src/utils/zkpid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const saveId = async (idType: string, id: Identity): Promise<void> => {
// console.log("anon id saved to storage!", idType, id)
}
} catch (error) {
console.error('Store Err: ', error);
console.log('Store Err: ', error);
}
};

Expand Down

0 comments on commit e043447

Please sign in to comment.