Skip to content

Commit f42aaa6

Browse files
authored
feat: switch to duration cronjobs (#435)
In order to update prices and transaction scans on confirmations, we are switching to duration cronjobs which allow us to do every 20s Fixes: https://consensyssoftware.atlassian.net/browse/NWNT-216
1 parent 9a603f0 commit f42aaa6

8 files changed

Lines changed: 290 additions & 335 deletions

File tree

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v21.7.3
1+
v22.17.0

docs/contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Thank you for your interest in contributing to the Snap Solana Wallet project! T
66

77
- [MetaMask Flask](https://consensyssoftware.atlassian.net/wiki/x/IQCOB10) is required for testing the snap locally
88
- [NVM](https://github.com/creationix/nvm) to manage Node.js and avoid compatibility issues between different projects
9-
- Node.js `21.7.3` as specified in `.nvmrc`
9+
- Node.js `v22.17.0` as specified in `.nvmrc`
1010
- Yarn `3.8.6` is required due to MetaMask package compatibility
1111

1212
## 🚀 Quick Start

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
"yarn lint:fix"
3636
]
3737
},
38+
"resolutions": {
39+
"@metamask/snaps-sdk": "8.1.0"
40+
},
3841
"devDependencies": {
3942
"@commitlint/cli": "^17.7.1",
4043
"@commitlint/config-conventional": "^17.7.0",

packages/snap/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
"@metamask/key-tree": "9.1.2",
4444
"@metamask/keyring-api": "^18.0.0",
4545
"@metamask/keyring-snap-sdk": "^4.0.0",
46-
"@metamask/snaps-cli": "^7.2.0",
47-
"@metamask/snaps-jest": "8.12.0",
48-
"@metamask/snaps-sdk": "^7.1.0",
46+
"@metamask/snaps-cli": "^8.1.0",
47+
"@metamask/snaps-jest": "9.2.0",
48+
"@metamask/snaps-sdk": "^8.1.0",
4949
"@metamask/superstruct": "^3.1.0",
5050
"@metamask/utils": "11.4.0",
5151
"@noble/ed25519": "2.1.0",

packages/snap/snap.manifest.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snap-solana-wallet.git"
88
},
99
"source": {
10-
"shasum": "CGJCQcU/gwXmG51oX44op5db6mwEBogWvzfbBJZ26bs=",
10+
"shasum": "ZHnbLwNwlfVGCNclPGBifht43erMlK4dGRZkBNDzmB4=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",
@@ -39,14 +39,14 @@
3939
"endowment:cronjob": {
4040
"jobs": [
4141
{
42-
"expression": "* * * * *",
42+
"duration": "PT30S",
4343
"request": {
4444
"method": "refreshSend",
4545
"params": {}
4646
}
4747
},
4848
{
49-
"expression": "* * * * *",
49+
"duration": "PT20S",
5050
"request": {
5151
"method": "refreshConfirmationEstimation",
5252
"params": {}
@@ -90,6 +90,6 @@
9090
"snap_dialog": {},
9191
"snap_getPreferences": {}
9292
},
93-
"platformVersion": "7.1.0",
93+
"platformVersion": "8.1.0",
9494
"manifestVersion": "0.1"
9595
}

packages/snap/src/features/send/render.test.tsx

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable @typescript-eslint/naming-convention */
2-
import { installSnap } from '@metamask/snaps-jest';
2+
import type { CaipAssetType } from '@metamask/keyring-api';
3+
import { getMockAccount, installSnap } from '@metamask/snaps-jest';
34

45
import type { SpotPrices } from '../../core/clients/price-api/types';
56
import {
@@ -37,20 +38,21 @@ const solanaKeyringAccounts = [
3738
MOCK_SOLANA_KEYRING_ACCOUNT_1,
3839
];
3940

40-
const solanaAccountBalances = {
41-
[KnownCaip19Id.SolLocalnet]: {
42-
amount: '0.123456789',
43-
unit: SOL_SYMBOL,
44-
},
45-
'solana:123456789abcdef/token:address1': {
46-
amount: '0.123456789',
47-
unit: '',
48-
},
49-
'solana:123456789abcdef/token:address2': {
50-
amount: '0.123456789',
51-
unit: '',
52-
},
53-
};
41+
const solanaAccountBalances: Record<string, { amount: string; unit: string }> =
42+
{
43+
[KnownCaip19Id.SolLocalnet]: {
44+
amount: '0.123456789',
45+
unit: SOL_SYMBOL,
46+
},
47+
'solana:123456789abcdef/token:address1': {
48+
amount: '0.123456789',
49+
unit: '',
50+
},
51+
'solana:123456789abcdef/token:address2': {
52+
amount: '0.123456789',
53+
unit: '',
54+
},
55+
};
5456

5557
const mockSpotPrices: SpotPrices = {
5658
[KnownCaip19Id.SolLocalnet]: {
@@ -175,8 +177,14 @@ describe('Send', () => {
175177

176178
const initialState = {
177179
keyringAccounts: {
178-
[MOCK_SOLANA_KEYRING_ACCOUNT_0.id]: MOCK_SOLANA_KEYRING_ACCOUNT_0,
179-
[MOCK_SOLANA_KEYRING_ACCOUNT_1.id]: MOCK_SOLANA_KEYRING_ACCOUNT_1,
180+
[MOCK_SOLANA_KEYRING_ACCOUNT_0.id]: {
181+
...MOCK_SOLANA_KEYRING_ACCOUNT_0,
182+
entropySource: 'default',
183+
},
184+
[MOCK_SOLANA_KEYRING_ACCOUNT_1.id]: {
185+
...MOCK_SOLANA_KEYRING_ACCOUNT_1,
186+
entropySource: 'alternative',
187+
},
180188
},
181189
assets: {
182190
[MOCK_SOLANA_KEYRING_ACCOUNT_0.id]: solanaAccountBalances,
@@ -202,6 +210,34 @@ describe('Send', () => {
202210
...mockPreferences,
203211
secretRecoveryPhrase: MOCK_SEED_PHRASE,
204212
unencryptedState: initialState,
213+
accounts: [
214+
getMockAccount({
215+
address: MOCK_SOLANA_KEYRING_ACCOUNT_0.address,
216+
selected: true,
217+
assets: Object.keys(solanaAccountBalances) as CaipAssetType[],
218+
scopes: [Network.Localnet],
219+
}),
220+
getMockAccount({
221+
address: MOCK_SOLANA_KEYRING_ACCOUNT_1.address,
222+
selected: false,
223+
assets: Object.keys(solanaAccountBalances) as CaipAssetType[],
224+
scopes: [Network.Localnet],
225+
}),
226+
],
227+
assets: {
228+
[KnownCaip19Id.SolLocalnet]: {
229+
symbol: 'SOL',
230+
name: 'Solana',
231+
},
232+
'solana:123456789abcdef/token:address1': {
233+
symbol: 'EURO-COIN',
234+
name: 'Euro Coin',
235+
},
236+
'solana:123456789abcdef/token:address2': {
237+
symbol: 'USDC',
238+
name: 'USDC',
239+
},
240+
},
205241
},
206242
});
207243

packages/snap/src/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,11 @@ export const onCronjob: OnCronjobHandler = async ({ request }) => {
186186
const result = await withCatchAndThrowSnapError(async () => {
187187
/**
188188
* Don't run cronjobs if client is locked or inactive
189-
* - We dont want to call cronjobs if the client is locked
190-
* - We Dont want to call cronjobs if the client is inactive (except if we havent run a cronjob in the last 15 minutes)
189+
* - We don't want to call cronjobs if the client is locked
190+
* - We don't want to call cronjobs if the client is inactive
191+
* (except if we haven't run a cronjob in the last 30 minutes)
191192
*/
192-
const { locked, active } =
193-
(await getClientStatus()) as GetClientStatusResult & {
194-
active: boolean | undefined; // FIXME: Remove this once the snap SDK is updated
195-
};
193+
const { locked, active } = await getClientStatus();
196194

197195
logger.log('[🔑 onCronjob] Client status', { locked, active });
198196

0 commit comments

Comments
 (0)