Skip to content

Commit

Permalink
fix: iOS 15 usage and bump version (#513)
Browse files Browse the repository at this point in the history
# Motivation

It was reported that the last version of NNS dapp shipped with SvelteKit v2 and per extension Rollup v4 was not usable on iOS 15 (iOS 17 was fine). Afternarrowing down the issue I figured out that the root cause of the issue was the usage of a static variable using within an object parameter.

# Error stacktrace on iOS v15

```
Unhandled Promise Rejection: SyntaxError: Unexpected token '{'
```

# Changes

- Replace static usage of `SubAccount.ZERO` with an object to fix the issue
- Add entry in CHANGELOG
- Bump version to release the patch to npm asap.

# Screenshot

![image](https://github.com/dfinity/ic-js/assets/16886711/f6581810-d0de-4f74-bcbf-3133fb31f112)

# Test

The fix was tested locally by bundling the library and including it in NNS dapp which was build and served `npx serve public` + `npx local-ssl-proxy --source 3001 --target 3000`. Finally the fix was validated by loading https://locahost:3001 in Xcode simulator with iOS 15.4.
  • Loading branch information
peterpeterparker authored Jan 9, 2024
1 parent 9009305 commit 0241480
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 11 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
# 2024.01.09-1115Z

## Overview

The current status of the libraries at the time of the release is as follows:

| Library | Version | Status |
| ------------------------ | ------- | ---------- |
| `@dfinity/ckbtc` | v2.1.0 | Unchanged |
| `@dfinity/cketh` | v0.0.1 | Unchanged |
| `@dfinity/cmc` | v2.1.0 | Unchanged |
| `@dfinity/ic-management` | v2.1.0 | Unchanged |
| `@dfinity/ledger-icp` | v2.1.1 | Patched 🤕 |
| `@dfinity/ledger-icrc` | v2.1.0 | Unchanged |
| `@dfinity/nns` | v3.1.0 | Unchanged |
| `@dfinity/nns-proto` | v1.0.0 | Unchanged |
| `@dfinity/sns` | v2.1.0 | Unchanged |
| `@dfinity/utils` | v2.0.0 | Unchanged️ |

## Fix

- When `@dfinity/ledger-icp` is bundled with Rollup v4, it leads to an incompatibility issue with iOS 15.

# 2024.01.03-1115Z

## Overview
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dfinity/ic-js",
"version": "2024.01.03-1115Z",
"version": "2024.01.09-1115Z",
"description": "A collection of library for interfacing with the Internet Computer.",
"license": "Apache-2.0",
"workspaces": [
Expand Down
2 changes: 1 addition & 1 deletion packages/ledger-icp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const data = await metadata();
| -------------- | ------------------ |
| `toUint8Array` | `() => Uint8Array` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger-icp/src/account_identifier.ts#L111)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ledger-icp/src/account_identifier.ts#L109)

### :factory: LedgerCanister

Expand Down
2 changes: 1 addition & 1 deletion packages/ledger-icp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dfinity/ledger-icp",
"version": "2.1.0",
"version": "2.1.1",
"description": "A library for interfacing with the ICP ledger on the Internet Computer.",
"license": "Apache-2.0",
"main": "dist/cjs/index.cjs.js",
Expand Down
6 changes: 4 additions & 2 deletions packages/ledger-icp/src/account_identifier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ describe("SubAccount", () => {
});

it("defines ZERO as a 32-byte zeroed array", () => {
expect(SubAccount.ZERO.toUint8Array()).toEqual(new Uint8Array(32).fill(0));
expect(SubAccount.fromID(0).toUint8Array()).toEqual(
new Uint8Array(32).fill(0),
);
});

it("can be initialized from a principal", () => {
Expand Down Expand Up @@ -96,7 +98,7 @@ describe("AccountIdentifier", () => {
principal: Principal.fromText(
"bwz3t-ercuj-owo6s-4adfr-sbu4o-l72hg-kfhc5-5sapm-tj6bn-3scho-uqe",
),
subAccount: SubAccount.ZERO,
subAccount: SubAccount.fromID(0),
}).toHex(),
).toBe("df4ad42194201b15ecbbe66ff68559a126854d8141fd935c5bd53433c2fb28d4");
});
Expand Down
4 changes: 1 addition & 3 deletions packages/ledger-icp/src/account_identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AccountIdentifier {

public static fromPrincipal({
principal,
subAccount = SubAccount.ZERO,
subAccount = SubAccount.fromID(0),
}: {
principal: Principal;
subAccount?: SubAccount;
Expand Down Expand Up @@ -106,8 +106,6 @@ export class SubAccount {
return new SubAccount(bytes);
}

public static ZERO: SubAccount = this.fromID(0);

public toUint8Array(): Uint8Array {
return this.bytes;
}
Expand Down

0 comments on commit 0241480

Please sign in to comment.