-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
callback works server side too (#450)
- Loading branch information
1 parent
fb57802
commit 47e0d35
Showing
3 changed files
with
57 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Wallet } from '@near-wallet-selector/core'; | ||
|
||
type Environment = 'client' | 'server'; | ||
|
||
const getEnvironment = (): Environment => { | ||
if (typeof window !== 'undefined') { | ||
return 'client'; | ||
} else { | ||
return 'server'; | ||
} | ||
}; | ||
|
||
const currentEnv: Environment = getEnvironment(); | ||
|
||
|
||
export const callbackSideCheck = ( | ||
callbackUrl: string | undefined, | ||
wallet: Wallet, | ||
): string => { | ||
let callbackFinal = callbackUrl; | ||
|
||
if (currentEnv === 'client') { | ||
const shouldGetFromMbjs = callbackUrl?.length < 1 || callbackUrl === undefined && | ||
window?.['mbjs']?.callbackUrl && window?.['mbjs']?.callbackUrl.length > 0; | ||
|
||
if (wallet?.id == 'mintbase-wallet') { | ||
if (callbackUrl?.length < 1 || callbackUrl === undefined) { | ||
let mbjsCallbackUrl = ''; | ||
|
||
if ( | ||
window?.['mbjs']?.callbackUrl && | ||
window?.['mbjs']?.callbackUrl.length > 0 | ||
) { | ||
mbjsCallbackUrl = window?.['mbjs']?.callbackUrl; | ||
} | ||
|
||
const globalCBUrl = | ||
localStorage?.getItem('mintbase-wallet:callback_url') || mbjsCallbackUrl; | ||
|
||
callbackFinal = globalCBUrl; | ||
} | ||
} | ||
|
||
if (shouldGetFromMbjs) { | ||
callbackFinal = window?.['mbjs']?.callbackUrl || ''; | ||
} | ||
} | ||
|
||
// Return the final callback URL. | ||
return callbackFinal; | ||
}; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters