Skip to content

Commit 4b8677d

Browse files
authored
Merge branch 'main' into feat/ID-3321
2 parents 072dc68 + 4ccd3f2 commit 4b8677d

File tree

6 files changed

+75
-124
lines changed

6 files changed

+75
-124
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package.json @immutable/passport
1717
/packages/passport @immutable/passport
1818
/packages/x-provider @immutable/passport
1919
/packages/checkout @immutable/passport
20-
/packages/checkout/widgets-lib @immutable/passport
20+
/packages/checkout/widgets-lib @immutable/gamefi
2121
/packages/blockchain-data @immutable/activation
2222
/packages/minting-backend @shineli1984
2323
/packages/webhook @shineli1984

packages/checkout/widgets-lib/rollup.config.js

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,37 @@ const PRODUCTION = 'production';
1010

1111
const isProduction = process.env.NODE_ENV === PRODUCTION
1212

13-
const defaultPlugins = [
14-
json(),
15-
replace({
16-
preventAssignment: true,
17-
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || PRODUCTION),
18-
}),
19-
]
20-
21-
const productionPlugins = [
22-
commonjs(),
23-
]
24-
25-
const getPlugins = () => {
26-
if (process.env.NODE_ENV !== PRODUCTION) {
27-
return defaultPlugins;
28-
}
29-
30-
return [
31-
...defaultPlugins,
32-
...productionPlugins
33-
];
34-
}
35-
3613
/**
37-
* @type {import('rollup').RollupOptions[]}
14+
* @type {import('rollup').RollupOptions}
3815
*/
39-
export default [
16+
export default
4017
// browser bundle
4118
{
4219
input: 'src/index.ts',
4320
treeshake: 'smallest',
4421
output: {
4522
dir: 'dist/browser',
4623
format: 'es',
47-
inlineDynamicImports: !isProduction,
24+
inlineDynamicImports: true,
4825
},
4926
plugins: [
5027
isProduction ? typescript({customConditions: ["default"], declaration: false, outDir: 'dist/browser'})
5128
: swc.rollup({ jsc: {
5229
transform: { react: { development: true, runtime: 'automatic' }},
5330
} }),
54-
resolve({
55-
browser: true,
56-
dedupe: ['react', 'react-dom'],
57-
exportConditions: ['default', 'browser'],
58-
}),
31+
...(isProduction ? [
32+
resolve({
33+
browser: true,
34+
dedupe: ['react', 'react-dom'],
35+
exportConditions: ['default', 'browser'],
36+
})
37+
] : []),
5938
nodePolyfills(),
60-
...getPlugins(),
39+
json(),
40+
replace({
41+
preventAssignment: true,
42+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || PRODUCTION),
43+
}),
44+
commonjs(),
6145
],
62-
},
63-
]
46+
}

packages/checkout/widgets-lib/src/widgets/swap/components/SwapForm.tsx

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
useContext, useEffect, useMemo, useState,
44
} from 'react';
55
import {
6-
Box, ButtCon, Heading, Icon, OptionKey, Tooltip,
6+
Box, ButtCon, Heading, Icon, OptionKey, Tooltip, Body,
77
} from '@biom3/react';
88
import { isAddressSanctioned, TokenInfo, WidgetTheme } from '@imtbl/checkout-sdk';
99

@@ -42,7 +42,6 @@ import { CoinSelectorOptionProps } from '../../../components/CoinSelector/CoinSe
4242
import { useInterval } from '../../../lib/hooks/useInterval';
4343
import { NotEnoughImx } from '../../../components/NotEnoughImx/NotEnoughImx';
4444
import { SharedViews, ViewActions, ViewContext } from '../../../context/view-context/ViewContext';
45-
import { UnableToSwap } from './UnableToSwap';
4645
import { ConnectLoaderContext } from '../../../context/connect-loader-context/ConnectLoaderContext';
4746
import useDebounce from '../../../lib/hooks/useDebounce';
4847
import { CancellablePromise } from '../../../lib/async/cancellablePromise';
@@ -122,6 +121,7 @@ export function SwapForm({ data, theme, cancelAutoProceed }: SwapFromProps) {
122121

123122
// Quote
124123
const [quote, setQuote] = useState<TransactionResponse | null>(null);
124+
const [quoteError, setQuoteError] = useState<string>('');
125125
const [gasFeeValue, setGasFeeValue] = useState<string>('');
126126
const [gasFeeToken, setGasFeeToken] = useState<TokenInfo | undefined>(undefined);
127127
const [gasFeeFiatValue, setGasFeeFiatValue] = useState<string>('');
@@ -148,7 +148,6 @@ export function SwapForm({ data, theme, cancelAutoProceed }: SwapFromProps) {
148148

149149
// Drawers
150150
const [showNotEnoughImxDrawer, setShowNotEnoughImxDrawer] = useState(false);
151-
const [showUnableToSwapDrawer, setShowUnableToSwapDrawer] = useState(false);
152151
const [showNetworkSwitchDrawer, setShowNetworkSwitchDrawer] = useState(false);
153152

154153
const [showTxnRejectedState, setShowTxnRejectedState] = useState(false);
@@ -217,9 +216,8 @@ export function SwapForm({ data, theme, cancelAutoProceed }: SwapFromProps) {
217216
network,
218217
]);
219218

220-
const openUnableToSwapDrawer = useCallback((error: any) => {
221-
setShowNotEnoughImxDrawer(false);
222-
setShowUnableToSwapDrawer(true);
219+
const onQuoteError = useCallback((error: any) => {
220+
setQuoteError(error.message);
223221
track({
224222
userJourney: UserJourney.SWAP,
225223
screen: 'SwapCoins',
@@ -262,6 +260,7 @@ export function SwapForm({ data, theme, cancelAutoProceed }: SwapFromProps) {
262260
setFromTokenError('');
263261
setToAmountError('');
264262
setToTokenError('');
263+
setQuoteError('');
265264
};
266265

267266
const resetQuote = () => {
@@ -349,7 +348,7 @@ export function SwapForm({ data, theme, cancelAutoProceed }: SwapFromProps) {
349348
console.error('Error fetching quote.', error);
350349

351350
resetQuote();
352-
openUnableToSwapDrawer(error);
351+
onQuoteError(error);
353352
}
354353
}
355354

@@ -425,7 +424,7 @@ export function SwapForm({ data, theme, cancelAutoProceed }: SwapFromProps) {
425424
} catch (error: any) {
426425
if (!error.cancelled) {
427426
resetQuote();
428-
openUnableToSwapDrawer(error);
427+
onQuoteError(error);
429428
}
430429
}
431430

@@ -741,7 +740,6 @@ export function SwapForm({ data, theme, cancelAutoProceed }: SwapFromProps) {
741740
};
742741

743742
const openNotEnoughImxDrawer = () => {
744-
setShowUnableToSwapDrawer(false);
745743
setShowNotEnoughImxDrawer(true);
746744
};
747745

@@ -766,7 +764,8 @@ export function SwapForm({ data, theme, cancelAutoProceed }: SwapFromProps) {
766764
if (validateToTokenError) setToTokenError(validateToTokenError);
767765
let isSwapFormValid = true;
768766
if (
769-
validateFromTokenError
767+
quoteError
768+
|| validateFromTokenError
770769
|| validateToTokenError
771770
|| (validateFromAmountError && direction === SwapDirection.FROM)
772771
|| (validateToAmountError && direction === SwapDirection.TO)) isSwapFormValid = false;
@@ -1083,6 +1082,27 @@ export function SwapForm({ data, theme, cancelAutoProceed }: SwapFromProps) {
10831082
/>
10841083
)}
10851084
</Box>
1085+
{quoteError && (
1086+
<Box sx={{
1087+
paddingX: 'base.spacing.x4',
1088+
pt: 'base.spacing.x3',
1089+
}}
1090+
>
1091+
<Body
1092+
size="xSmall"
1093+
weight="bold"
1094+
sx={{
1095+
color: 'base.color.text.status.fatal.primary',
1096+
}}
1097+
rc={<div />}
1098+
>
1099+
Unable to swap this token
1100+
</Body>
1101+
<Body size="xxSmall">
1102+
This token pairing isn&apos;t available to swap right now. Try another selection.
1103+
</Body>
1104+
</Box>
1105+
)}
10861106
{!autoProceed && (
10871107
<SwapButton
10881108
validator={SwapFormValidator}
@@ -1121,16 +1141,6 @@ export function SwapForm({ data, theme, cancelAutoProceed }: SwapFromProps) {
11211141
}}
11221142
onCloseDrawer={() => setShowNotEnoughImxDrawer(false)}
11231143
/>
1124-
<UnableToSwap
1125-
visible={showUnableToSwapDrawer}
1126-
onCloseDrawer={() => {
1127-
setShowUnableToSwapDrawer(false);
1128-
setFromToken(undefined);
1129-
setFromAmount('');
1130-
setToToken(undefined);
1131-
setToAmount('');
1132-
}}
1133-
/>
11341144
<NetworkSwitchDrawer
11351145
visible={showNetworkSwitchDrawer}
11361146
targetChainId={getL2ChainId(checkout?.config!)}

packages/checkout/widgets-lib/src/widgets/swap/components/UnableToSwap.tsx

Lines changed: 0 additions & 68 deletions
This file was deleted.

packages/passport/sdk/src/magic/magicProviderProxyFactory.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,17 @@ describe('MagicProviderProxyFactory', () => {
107107

108108
await expect(proxy.request!(params)).rejects.toThrow('ProviderProxy: Test error');
109109
});
110+
111+
it('should convert eth_requestAccounts to eth_accounts to avoid Magic overlay', async () => {
112+
const proxy = factory.createProxy(mockMagicClient);
113+
const params = { method: 'eth_requestAccounts' };
114+
(mockMagicClient.user.isLoggedIn as jest.Mock).mockResolvedValue(true);
115+
116+
await proxy.request!(params);
117+
118+
expect(mockMagicClient.user.isLoggedIn).toHaveBeenCalled();
119+
expect(mockRpcProvider.request).toHaveBeenCalledWith({ method: 'eth_accounts' });
120+
expect(mockRpcProvider.request).not.toHaveBeenCalledWith(params);
121+
});
110122
});
111123
});

packages/passport/sdk/src/magic/magicProviderProxyFactory.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ const shouldCheckMagicSession = (args: any[]): boolean => (
88
&& typeof args[0] === 'object'
99
&& 'method' in args[0]
1010
&& typeof args[0].method === 'string'
11-
&& ['personal_sign', 'eth_accounts'].includes(args[0].method)
11+
&& ['personal_sign', 'eth_accounts', 'eth_requestAccounts'].includes(args[0].method)
12+
);
13+
14+
const isEthRequestAccountsCall = (args: any[]): boolean => (
15+
args?.length > 0
16+
&& typeof args[0] === 'object'
17+
&& 'method' in args[0]
18+
&& typeof args[0].method === 'string'
19+
&& args[0].method === 'eth_requestAccounts'
1220
);
1321

1422
/**
@@ -47,6 +55,12 @@ export class MagicProviderProxyFactory {
4755
providerId: this.config.magicProviderId,
4856
});
4957
}
58+
59+
if (isEthRequestAccountsCall(args)) {
60+
// @ts-ignore - Calling eth_requestAccounts on the Magic RPC provider displays an overlay, so this
61+
// should be avoided - call eth_accounts instead.
62+
return target.request!({ method: 'eth_accounts' });
63+
}
5064
}
5165

5266
// @ts-ignore - Invoke the request method with the provided arguments

0 commit comments

Comments
 (0)