Skip to content

Commit

Permalink
Add bigint filter for jsondiffpatch (#3561)
Browse files Browse the repository at this point in the history
In the current implementation, `bigints` are treated as objects and are
incorrectly excluded from generated patches. This fixes `bigint` diffing
by adding a handler for these cases to the `jsondiffpatch` pipeline.

## To Test
- [x] Send assets
- [x] Check that balance changes after transaction succeeds

Latest build:
[extension-builds-3561](https://github.com/tahowallet/extension/suites/14449081920/artifacts/815732866)
(as of Thu, 20 Jul 2023 17:02:04 GMT).
  • Loading branch information
Shadowfiend authored Jul 20, 2023
2 parents 320b07f + fd8c798 commit 6a220e1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions background/differ.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DiffContext, Filter, create } from "jsondiffpatch"

const differ = create()

const bigintDiffFilter: Filter<DiffContext> = (context) => {
if (typeof context.left === "bigint" && typeof context.right === "bigint") {
if (context.left !== context.right) {
context.setResult([context.left, context.right])
}
}
}
bigintDiffFilter.filterName = "bigint"

differ.processor.pipes.diff.before("objects", bigintDiffFilter)

export const diff = differ.diff.bind(differ)
export const patch = differ.patch.bind(differ)
export type { Delta } from "jsondiffpatch"
2 changes: 1 addition & 1 deletion background/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import browser from "webextension-polyfill"

import { Store as ProxyStore } from "webext-redux"
import { Delta, patch as patchDeepDiff } from "jsondiffpatch"
import { produce } from "immer"
import { AnyAction } from "@reduxjs/toolkit"

import { Delta, patch as patchDeepDiff } from "./differ"
import Main from "./main"
import { encodeJSON, decodeJSON } from "./lib/utils"

Expand Down
2 changes: 1 addition & 1 deletion background/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import browser, { runtime } from "webextension-polyfill"
import { alias, wrapStore } from "webext-redux"
import { diff as deepDiff } from "jsondiffpatch"
import { configureStore, isPlain, Middleware } from "@reduxjs/toolkit"
import { devToolsEnhancer } from "@redux-devtools/remote"
import { PermissionRequest } from "@tallyho/provider-bridge-shared"
import { debounce } from "lodash"
import { utils } from "ethers"

import { diff as deepDiff } from "./differ"
import {
decodeJSON,
encodeJSON,
Expand Down

0 comments on commit 6a220e1

Please sign in to comment.