Skip to content

Commit

Permalink
introduce serverSide
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahZinsmeister committed May 2, 2022
1 parent 3becf08 commit e082cde
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/coinbase-wallet/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class CoinbaseWallet extends Connector {
constructor(actions: Actions, options: CoinbaseWalletSDKOptions, connectEagerly = false) {
super(actions)

if (connectEagerly && typeof window === 'undefined') {
if (connectEagerly && this.serverSide) {
throw new Error('connectEagerly = true is invalid for SSR, instead use the connectEagerly method in a useEffect')
}

Expand Down
2 changes: 1 addition & 1 deletion packages/eip1193/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class EIP1193 extends Connector {
constructor(actions: Actions, provider: Provider, connectEagerly = false) {
super(actions)

if (connectEagerly && typeof window === 'undefined') {
if (connectEagerly && this.serverSide) {
throw new Error('connectEagerly = true is invalid for SSR, instead use the connectEagerly method in a useEffect')
}

Expand Down
4 changes: 2 additions & 2 deletions packages/gnosis-safe/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class GnosisSafe extends Connector {
constructor(actions: Actions, connectEagerly = false, options?: Opts) {
super(actions)

if (connectEagerly && typeof window === 'undefined') {
if (connectEagerly && this.serverSide) {
throw new Error('connectEagerly = true is invalid for SSR, instead use the connectEagerly method in a useEffect')
}

Expand All @@ -41,7 +41,7 @@ export class GnosisSafe extends Connector {

// check if we're in an iframe
private get inIframe() {
if (typeof window === 'undefined') return false
if (this.serverSide) return false
if (window !== window.parent) return true
return false
}
Expand Down
2 changes: 1 addition & 1 deletion packages/metamask/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class MetaMask extends Connector {
constructor(actions: Actions, connectEagerly = false, options?: Parameters<typeof detectEthereumProvider>[0]) {
super(actions)

if (connectEagerly && typeof window === 'undefined') {
if (connectEagerly && this.serverSide) {
throw new Error('connectEagerly = true is invalid for SSR, instead use the connectEagerly method in a useEffect')
}

Expand Down
2 changes: 1 addition & 1 deletion packages/network/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Network extends Connector {
) {
super(actions)

if (connectEagerly && typeof window === 'undefined') {
if (connectEagerly && this.serverSide) {
throw new Error('connectEagerly = true is invalid for SSR, instead use the activate method in a useEffect')
}

Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export abstract class Connector {
this.actions = actions
}

protected get serverSide() {
return typeof window === 'undefined'
}

/**
* Attempt to initiate a connection, failing silently
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/url/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Url extends Connector {
constructor(actions: Actions, url: url | JsonRpcProvider, connectEagerly = false) {
super(actions)

if (connectEagerly && typeof window === 'undefined') {
if (connectEagerly && this.serverSide) {
throw new Error('connectEagerly = true is invalid for SSR, instead use the activate method in a useEffect')
}

Expand Down
2 changes: 1 addition & 1 deletion packages/walletconnect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class WalletConnect extends Connector {
constructor(actions: Actions, options: WalletConnectOptions, connectEagerly = false, treatModalCloseAsError = true) {
super(actions)

if (connectEagerly && typeof window === 'undefined') {
if (connectEagerly && this.serverSide) {
throw new Error('connectEagerly = true is invalid for SSR, instead use the connectEagerly method in a useEffect')
}

Expand Down

0 comments on commit e082cde

Please sign in to comment.