Skip to content

Commit dcdcdbd

Browse files
authored
Merge branch 'main' into NNT-406-track-events-snap_trackEvent
2 parents 1a29767 + 5f3b1ad commit dcdcdbd

10 files changed

Lines changed: 66 additions & 40 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solana-wallet-snap-monorepo",
3-
"version": "1.33.0",
3+
"version": "1.33.1",
44
"private": true,
55
"description": "",
66
"homepage": "https://github.com/MetaMask/snap-solana-wallet#readme",

packages/snap/CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.33.1]
11+
12+
### Fixed
13+
14+
- Max button not working when balace is lower than rent + fee ([#419](https://github.com/MetaMask/snap-solana-wallet/pull/419))
15+
- Transaction scan when api fails ([#419](https://github.com/MetaMask/snap-solana-wallet/pull/419))
16+
1017
## [1.33.0]
1118

1219
### Added
@@ -658,7 +665,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
658665
- Sonarcloud to github workflow ([#25](https://github.com/MetaMask/snap-solana-wallet/pull/25))
659666
- Snap setup
660667

661-
[Unreleased]: https://github.com/MetaMask/snap-solana-wallet/compare/v1.33.0...HEAD
668+
[Unreleased]: https://github.com/MetaMask/snap-solana-wallet/compare/v1.33.1...HEAD
669+
[1.33.1]: https://github.com/MetaMask/snap-solana-wallet/compare/v1.33.0...v1.33.1
662670
[1.33.0]: https://github.com/MetaMask/snap-solana-wallet/compare/v1.32.0...v1.33.0
663671
[1.32.0]: https://github.com/MetaMask/snap-solana-wallet/compare/v1.31.2...v1.32.0
664672
[1.31.2]: https://github.com/MetaMask/snap-solana-wallet/compare/v1.31.1...v1.31.2

packages/snap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamask/solana-wallet-snap",
3-
"version": "1.33.0",
3+
"version": "1.33.1",
44
"description": "A Solana wallet Snap.",
55
"repository": {
66
"type": "git",

packages/snap/snap.manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"version": "1.33.0",
2+
"version": "1.33.1",
33
"description": "Manage Solana using MetaMask",
44
"proposedName": "Solana",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/MetaMask/snap-solana-wallet.git"
88
},
99
"source": {
10-
"shasum": "7HPZTKQiA1U8iDDfA1vTbxJUocgwVyTOoiPaNdApkiM=",
10+
"shasum": "0G8PXZNx7ioU2jbDWfX7Qv94bxORrt2q1mgWZj/ajow=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snap/src/features/confirmation/views/ConfirmTransactionRequest/render.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ export async function render(
183183
options,
184184
})
185185
.then(async (scan) => {
186-
updatedContext2.scanFetchStatus = 'fetched';
187186
updatedContext2.scan = scan;
187+
updatedContext2.scanFetchStatus = scan ? 'fetched' : 'error';
188188
})
189189
.catch(() => {
190190
updatedContext2.scan = null;

packages/snap/src/features/send/components/AmountInput/AmountInput.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ type AmountInputProps = {
1818
currency: string;
1919
currencyType: SendCurrencyType;
2020
locale: Locale;
21-
error?: string;
2221
swapCurrencyButtonDisabled?: boolean;
2322
};
2423

@@ -28,7 +27,6 @@ export const AmountInput: SnapComponent<AmountInputProps> = ({
2827
tokenSymbol,
2928
currency,
3029
currencyType,
31-
error,
3230
locale,
3331
swapCurrencyButtonDisabled = false,
3432
}) => {
@@ -39,7 +37,7 @@ export const AmountInput: SnapComponent<AmountInputProps> = ({
3937
: tokenSymbol;
4038

4139
return (
42-
<Field label={translate('send.amountField')} error={error}>
40+
<Field label={translate('send.amountField')}>
4341
<Input
4442
name={name}
4543
type="number"

packages/snap/src/features/send/validation/form.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ describe('send form validation', () => {
126126
scope: Network.Testnet,
127127
currencyType: SendCurrencyType.TOKEN,
128128
feeEstimatedInSol: '0.000005',
129+
selectedTokenMetadata: {
130+
symbol: 'SOL',
131+
},
129132
balances: {
130133
[MOCK_SOLANA_KEYRING_ACCOUNT_0.id]: {
131134
[KnownCaip19Id.SolTestnet]: {
@@ -155,7 +158,7 @@ describe('send form validation', () => {
155158
const context = createSolContext();
156159
const validator = amountInput(context);
157160
expect(validator('0')).toStrictEqual({
158-
message: '',
161+
message: 'Amount must be greater than 0.002',
159162
value: '0',
160163
});
161164
});
@@ -164,7 +167,7 @@ describe('send form validation', () => {
164167
const context = createSolContext();
165168
const validator = amountInput(context);
166169
expect(validator('1.5')).toStrictEqual({
167-
message: 'Insufficient balance',
170+
message: 'Insufficient balance: 1 SOL',
168171
value: '1.5',
169172
});
170173
});
@@ -213,6 +216,9 @@ describe('send form validation', () => {
213216
scope: Network.Testnet,
214217
currencyType: SendCurrencyType.TOKEN,
215218
feeEstimatedInSol: '0.000005',
219+
selectedTokenMetadata: {
220+
symbol: 'EURC',
221+
},
216222
balances: {
217223
[MOCK_SOLANA_KEYRING_ACCOUNT_0.id]: {
218224
[KnownCaip19Id.EurcDevnet]: {
@@ -260,7 +266,7 @@ describe('send form validation', () => {
260266
const context = createSplContext();
261267
const validator = amountInput(context);
262268
expect(validator('150')).toStrictEqual({
263-
message: 'Insufficient balance',
269+
message: 'Insufficient balance: 100 EURC',
264270
value: '150',
265271
});
266272
});

packages/snap/src/features/send/validation/form.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export const amountInput = (context: SendContext) => {
133133
minimumBalanceForRentExemptionSol,
134134
preferences: { locale },
135135
feeEstimatedInSol,
136+
selectedTokenMetadata,
136137
} = context;
137138
const translate = i18n(locale);
138139

@@ -153,33 +154,19 @@ export const amountInput = (context: SendContext) => {
153154
const minimumBalanceForRentExemptionLamports = solToLamports(
154155
minimumBalanceForRentExemptionSol ?? '0',
155156
);
156-
157-
// If the value parses to 0, it's invalid but we don't want to show an error
158-
if (tokenAmountLamports.isZero()) {
159-
return { message: '', value };
160-
}
157+
const solBalance = getNativeTokenBalance(context);
158+
const solBalanceLamports = solToLamports(solBalance);
159+
const isNativeToken = getIsNativeToken(context);
161160

162161
// If you try to send more than your balance, it's invalid
163162
const isAmountGreaterThanBalance = tokenAmountLamports.gt(balanceLamports);
164163
if (isAmountGreaterThanBalance) {
165164
return {
166-
message: translate('send.insufficientBalance'),
165+
message: `${translate('send.insufficientBalance')}: ${balance} ${selectedTokenMetadata?.symbol ?? ''}`,
167166
value,
168167
};
169168
}
170169

171-
// If you have 0 SOL, you can't pay for the fee, it's invalid
172-
const solBalance = getNativeTokenBalance(context);
173-
const solBalanceLamports = solToLamports(solBalance);
174-
if (solBalanceLamports.isZero()) {
175-
return {
176-
message: translate('send.insuffientSolToCoverFee'),
177-
value,
178-
};
179-
}
180-
181-
const isNativeToken = getIsNativeToken(context);
182-
183170
if (isNativeToken) {
184171
// If the value is lower than the minimum balance for rent exemption, it's invalid
185172
const valueLowerThanMinimum = tokenAmountLamports.lt(
@@ -225,6 +212,19 @@ export const amountInput = (context: SendContext) => {
225212
}
226213
}
227214

215+
// If the value parses to 0, it's invalid but we don't want to show an error
216+
if (tokenAmountLamports.isZero()) {
217+
return { message: '', value };
218+
}
219+
220+
// If you have 0 SOL, you can't pay for the fee, it's invalid
221+
if (solBalanceLamports.isZero()) {
222+
return {
223+
message: translate('send.insuffientSolToCoverFee'),
224+
value,
225+
};
226+
}
227+
228228
return null;
229229
};
230230
};

packages/snap/src/features/send/views/SendForm/SendForm.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ export const SendForm = ({
105105

106106
const showClearAddressButton = Boolean(toAddress && toAddress.length > 0);
107107

108+
const amountInputIsError = Boolean(
109+
validation?.[SendFormNames.AmountInput]?.message,
110+
);
111+
112+
const balanceText = amountInputIsError
113+
? (validation?.[SendFormNames.AmountInput]?.message ?? '')
114+
: `${translate('send.balance')}: ${balance}`;
115+
108116
const canReview =
109117
fromAccountId.length > 0 &&
110118
(amount ? amount.length > 0 : false) &&
@@ -178,7 +186,6 @@ export const SendForm = ({
178186
</Field>
179187
<AmountInput
180188
name={SendFormNames.AmountInput}
181-
error={validation?.[SendFormNames.AmountInput]?.message ?? ''}
182189
currencyType={currencyType}
183190
tokenSymbol={tokenSymbol}
184191
currency={currency}
@@ -189,14 +196,19 @@ export const SendForm = ({
189196
}
190197
/>
191198
</Box>
192-
<Box direction="horizontal" alignment="space-between" center>
193-
{balance ? (
194-
<Text size="sm" color="muted">{`${translate(
195-
'send.balance',
196-
)}: ${balance}`}</Text>
197-
) : (
198-
<Box>{null}</Box>
199-
)}
199+
<Box
200+
direction="horizontal"
201+
alignment="space-between"
202+
crossAlignment="start"
203+
>
204+
<Box direction="vertical" alignment="start">
205+
<Text
206+
size="sm"
207+
color={amountInputIsError ? 'error' : 'muted'}
208+
>
209+
{balanceText}
210+
</Text>
211+
</Box>
200212
<Button
201213
size="sm"
202214
name={SendFormNames.MaxAmountButton}

packages/snap/src/features/send/views/SendForm/events.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ async function onMaxAmountButtonClick({
295295

296296
const maxAmountLamports = BigNumber.maximum(
297297
balanceInLamportsAfterCost,
298-
BigNumber(0),
298+
balanceInLamportsAfterCost.isNegative()
299+
? balanceInLamports
300+
: BigNumber(0),
299301
);
300302

301303
const maxAmountSol = lamportsToSol(maxAmountLamports);

0 commit comments

Comments
 (0)