Skip to content

Commit

Permalink
[DX-2433] feat: add registration functions to game bridge (#1190)
Browse files Browse the repository at this point in the history
  • Loading branch information
nattb8 authored Nov 21, 2023
1 parent 1eec8fc commit 99814f6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
26 changes: 26 additions & 0 deletions packages/game-bridge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const PASSPORT_FUNCTIONS = {
logout: 'logout',
getEmail: 'getEmail',
imx: {
isRegisteredOffchain: 'isRegisteredOffchain',
registerOffchain: 'registerOffchain',
transfer: 'imxTransfer',
batchNftTransfer: 'imxBatchNftTransfer',
},
Expand Down Expand Up @@ -278,6 +280,30 @@ window.callFunction = async (jsonData: string) => { // eslint-disable-line no-un
});
break;
}
case PASSPORT_FUNCTIONS.imx.isRegisteredOffchain: {
console.log('PASSPORT_FUNCTIONS.imx.isRegisteredOffchain');
const registered = await providerInstance?.isRegisteredOffchain();
callbackToGame({
responseFor: fxName,
requestId,
success: true,
result: registered,
});
break;
}
case PASSPORT_FUNCTIONS.imx.registerOffchain: {
console.log('PASSPORT_FUNCTIONS.imx.registerOffchain');
const response = await providerInstance?.registerOffchain();
callbackToGame({
...{
responseFor: fxName,
requestId,
success: response !== null && response !== undefined,
},
...response,
});
break;
}
case PASSPORT_FUNCTIONS.imx.transfer: {
const unsignedTransferRequest = JSON.parse(data);
const response = await providerInstance?.transfer(unsignedTransferRequest);
Expand Down
23 changes: 19 additions & 4 deletions packages/passport/sdk/src/authManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export default class AuthManager {
formUrlEncodedHeader,
);
const newTokenResponse = response.data;
this.deviceCredentialsManager.saveCredentials(newTokenResponse);

return AuthManager.mapDeviceTokenResponseToDomainUserModel(newTokenResponse);
}
Expand Down Expand Up @@ -399,10 +400,24 @@ export default class AuthManager {
// eslint-disable-next-line no-async-promise-executor
this.refreshingPromise = new Promise(async (resolve, reject) => {
try {
const newOidcUser = await this.userManager.signinSilent();
if (newOidcUser) {
resolve(AuthManager.mapOidcUserToDomainModel(newOidcUser));
return;
if (this.config.crossSdkBridgeEnabled) {
const tokenResponse = this.checkStoredDeviceFlowCredentials();
if (tokenResponse) {
const refreshToken = tokenResponse?.refresh_token ?? null;
if (refreshToken) {
const newUser = await this.refreshToken(refreshToken);
if (newUser) {
resolve(newUser);
return;
}
}
}
} else {
const newOidcUser = await this.userManager.signinSilent();
if (newOidcUser) {
resolve(AuthManager.mapOidcUserToDomainModel(newOidcUser));
return;
}
}
resolve(null);
} catch (err) {
Expand Down

0 comments on commit 99814f6

Please sign in to comment.