Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "1.4.2",
"version": "1.4.3",
"description": "Manage Bitcoin using MetaMask",
"proposedName": "Bitcoin",
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/snap-bitcoin-wallet.git"
},
"source": {
"shasum": "QcEyQw877Qk+uanuNyo9sJ0NqTMPyy3gO5wlE+eFXNM=",
"shasum": "On9X6VsyK9Nr8Zs0DmfA0SCKFsO8ayVV2oqNlGDpMFc=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
18 changes: 10 additions & 8 deletions packages/snap/src/handlers/CronHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ describe('CronHandler', () => {
});
});

describe('fullScanSelectedAccounts', () => {
describe('syncSelectedAccounts', () => {
const mockAccounts = [
mock<BitcoinAccount>({ id: 'account-1' }),
mock<BitcoinAccount>({ id: 'account-2' }),
mock<BitcoinAccount>({ id: 'account-3' }),
];
const request = {
method: CronMethod.FullScanSelectedAccounts,
method: CronMethod.SyncSelectedAccounts,
params: { accountIds: ['account-1', 'account-2'] },
} as unknown as JsonRpcRequest;

Expand All @@ -150,12 +150,14 @@ describe('CronHandler', () => {
await handler.route(request);

expect(mockAccountUseCases.list).toHaveBeenCalled();
expect(mockAccountUseCases.fullScan).toHaveBeenCalledTimes(2);
expect(mockAccountUseCases.fullScan).toHaveBeenCalledWith(
expect(mockAccountUseCases.synchronize).toHaveBeenCalledTimes(2);
expect(mockAccountUseCases.synchronize).toHaveBeenCalledWith(
mockAccounts[0],
'metamask',
);
expect(mockAccountUseCases.fullScan).toHaveBeenCalledWith(
expect(mockAccountUseCases.synchronize).toHaveBeenCalledWith(
mockAccounts[1],
'metamask',
);
});

Expand All @@ -166,7 +168,7 @@ describe('CronHandler', () => {
});
await handler.route(request);

expect(mockAccountUseCases.fullScan).not.toHaveBeenCalled();
expect(mockAccountUseCases.synchronize).not.toHaveBeenCalled();
});

it('propagates errors from list', async () => {
Expand All @@ -178,14 +180,14 @@ describe('CronHandler', () => {

it('completes successfully even if some accounts fail to scan', async () => {
mockAccountUseCases.list.mockResolvedValue(mockAccounts);
mockAccountUseCases.fullScan
mockAccountUseCases.synchronize
.mockResolvedValueOnce(undefined)
.mockRejectedValueOnce(new Error('scan failed'));

const result = await handler.route(request);

expect(result).toBeUndefined();
expect(mockAccountUseCases.fullScan).toHaveBeenCalledTimes(2);
expect(mockAccountUseCases.synchronize).toHaveBeenCalledTimes(2);
});
});

Expand Down
14 changes: 7 additions & 7 deletions packages/snap/src/handlers/CronHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import type { SendFlowUseCases, AccountUseCases } from '../use-cases';
export enum CronMethod {
SynchronizeAccounts = 'synchronizeAccounts',
RefreshRates = 'refreshRates',
FullScanSelectedAccounts = 'fullScanSelectedAccounts',
SyncSelectedAccounts = 'syncSelectedAccounts',
FullScanAccount = 'fullScanAccount',
}

export const SendFormRefreshRatesRequest = object({
interfaceId: string(),
});

export const FullScanSelectedAccountsRequest = object({
export const SyncSelectedAccountsRequest = object({
accountIds: array(string()),
});

Expand Down Expand Up @@ -66,9 +66,9 @@ export class CronHandler {
assert(params, SendFormRefreshRatesRequest);
return this.#sendFlowUseCases.refresh(params.interfaceId);
}
case CronMethod.FullScanSelectedAccounts: {
assert(params, FullScanSelectedAccountsRequest);
return this.fullScanSelectedAccounts(params.accountIds);
case CronMethod.SyncSelectedAccounts: {
assert(params, SyncSelectedAccountsRequest);
return this.syncSelectedAccounts(params.accountIds);
}
case CronMethod.FullScanAccount: {
assert(params, FullScanAccountRequest);
Expand Down Expand Up @@ -112,7 +112,7 @@ export class CronHandler {
}
}

async fullScanSelectedAccounts(accountIds: string[]): Promise<void> {
async syncSelectedAccounts(accountIds: string[]): Promise<void> {
const accountIdSet = new Set(accountIds);
const allAccounts = await this.#accountsUseCases.list();

Expand All @@ -121,7 +121,7 @@ export class CronHandler {
);

const scanPromises = selectedAccounts.map(async (account) =>
this.#accountsUseCases.fullScan(account),
this.#accountsUseCases.synchronize(account, 'metamask'),
);

await Promise.allSettled(scanPromises);
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/handlers/KeyringHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export class KeyringHandler implements Keyring {
// Schedule immediate background job to perform full scan
await this.#snapClient.scheduleBackgroundEvent({
duration: 'PT1S',
method: CronMethod.FullScanSelectedAccounts,
method: CronMethod.SyncSelectedAccounts,
params: { accountIds: accounts },
});
}
Expand Down
4 changes: 4 additions & 0 deletions packages/snap/src/infra/jsx/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ export const displayCaip10 = (
): CaipAccountId => {
return `${networkToScope[network]}:${address}`;
};

export const displayNetwork = (network: Network): string => {
return network.charAt(0).toUpperCase() + network.slice(1);
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
displayCaip10,
displayExchangeAmount,
displayExplorerUrl,
displayNetwork,
isValidSnapLinkProtocol,
translate,
} from '../format';
Expand Down Expand Up @@ -62,7 +63,7 @@ export const UnifiedSendFormView: SnapComponent<UnifiedSendFormViewProps> = ({
{t('confirmation.estimatedChanges.send')}
</SnapText>
<Box direction="vertical" crossAlignment="end">
<Box direction="horizontal" alignment="center">
<Box direction="horizontal" center>
<SnapText color="error">
-{displayAmount(BigInt(amount), currency).replace(' BTC', '')}
</SnapText>
Expand Down Expand Up @@ -101,9 +102,9 @@ export const UnifiedSendFormView: SnapComponent<UnifiedSendFormViewProps> = ({
<SnapText fontWeight="medium" color="alternative">
{t('network')}
</SnapText>
<Box direction="horizontal" alignment="center">
<Box direction="horizontal" center>
<AssetIconInline network={network} variant="network" />
<SnapText>{network}</SnapText>
<SnapText>{displayNetwork(network)}</SnapText>
</Box>
</Box>
<Box>{null}</Box>
Expand Down