Skip to content

Commit

Permalink
mobile: don't include landline transfer for old mobile versions (#1309)
Browse files Browse the repository at this point in the history
* mobile: don't include landline transfer for old mobile versions

* fix

* use semver package

* add logging for assert
  • Loading branch information
andrewliu08 authored Sep 6, 2024
1 parent f223abe commit 2214ddc
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 13 deletions.
10 changes: 8 additions & 2 deletions apps/daimo-mobile/src/view/screen/history/HistoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,15 @@ function TransferClogRow({
const nav = useNav();
const address = account.address;

assert(transferClog.amount > 0);
assert(
transferClog.amount > 0,
`TransferClogRow amount should be greater than 0. amount: ${transferClog.amount}`
);
const [from, to] = getDisplayFromTo(transferClog);
assert([from, to].includes(getAddress(address)));
assert(
[from, to].includes(getAddress(address)),
`TransferClogRow from and to should include address. from: ${from}, to: ${to}`
);
const setBottomSheetDetailHeight = useContext(SetBottomSheetDetailHeight);

const otherContact = getTransferClogContact(transferClog, address);
Expand Down
16 changes: 14 additions & 2 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 packages/daimo-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"libhoney": "^4.1.0",
"obscenity": "^0.2.1",
"pg": "^8.11.0",
"semver": "^7.6.0",
"semver": "^7.6.3",
"userop": "^0.3.2",
"viem": "^1.19.15",
"ws": "^8.17.0",
Expand Down
31 changes: 24 additions & 7 deletions packages/daimo-api/src/api/getAccountHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
guessTimestampFromNum,
hasAccountName,
} from "@daimo/common";
import semver from "semver";
import semverLt from "semver/functions/lt";
import { Address } from "viem";

Expand Down Expand Up @@ -105,14 +106,25 @@ export async function getAccountHistory(
paymaster: Paymaster,
db: DB,
extApiCache: ExternalApiCache,
blockNumber: number
blockNumber: number,
version: string | undefined
): Promise<AccountHistoryResult> {
const eAcc = nameReg.getDaimoAccount(address);
assert(
eAcc != null && eAcc.name != null,
`${address} is not a Daimo account`
);
const startMs = performance.now();
// Split version string into appVersion and buildVersion
let appVersion: string | undefined;
if (version) {
const parts = version.split(" #");
appVersion = parts[0];
assert(
semver.valid(appVersion) != null,
`${version} is not a valid app version`
);
}
const log = `[API] getAccountHist: ${eAcc.name} ${address} since ${sinceBlockNum}`;
console.log(`${log}: starting`);

Expand Down Expand Up @@ -198,12 +210,17 @@ export async function getAccountHistory(
const landlineSessionKey = (await getLandlineSession(address)).key;
landlineSessionURL = getLandlineURL(address, landlineSessionKey);
landlineAccounts = await getLandlineAccounts(address);
const landlineTransfers = await getLandlineTransfers(address);
transferClogs = addLandlineTransfers(
landlineTransfers,
transferClogs,
chainConfig.daimoChain
);
// Support for displaying landline transfers in the mobile app was added
// in version 1.9.7 and doesn't support backcompat.
// Only add landline transfers if the app version is > 1.9.6
if (appVersion && semver.gt(appVersion, "1.9.6")) {
const landlineTransfers = await getLandlineTransfers(address);
transferClogs = addLandlineTransfers(
landlineTransfers,
transferClogs,
chainConfig.daimoChain
);
}
}

// Get named accounts
Expand Down
8 changes: 7 additions & 1 deletion packages/daimo-api/src/server/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ export function createRouter(
.query(async (opts) => {
const { inviteCode, sinceBlockNum, lang } = opts.input;
const address = getAddress(opts.input.address);

const version = opts.ctx.req.headers["x-daimo-version"] as
| string
| undefined;

return getAccountHistory(
opts.ctx,
address,
Expand All @@ -366,7 +371,8 @@ export function createRouter(
paymaster,
db,
extApiCache,
watcher.latestBlock().number
watcher.latestBlock().number,
version
);
}),

Expand Down

0 comments on commit 2214ddc

Please sign in to comment.