-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { | ||
generateInboxId as generateInboxIdBinding, | ||
getInboxIdForAddress as getInboxIdForAddressBinding, | ||
} from "@xmtp/node-bindings"; | ||
import { ApiUrls, type XmtpEnv } from "@/Client"; | ||
|
||
export const generateInboxId = (accountAddress: string): string => { | ||
return generateInboxIdBinding(accountAddress); | ||
}; | ||
|
||
export const getInboxIdForAddress = async ( | ||
accountAddress: string, | ||
env: XmtpEnv = "dev", | ||
) => { | ||
const host = ApiUrls[env]; | ||
const isSecure = host.startsWith("https"); | ||
return getInboxIdForAddressBinding(host, isSecure, accountAddress); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { generateInboxId, getInboxIdForAddress } from "@/helpers/inboxId"; | ||
import { createRegisteredClient, createUser } from "@test/helpers"; | ||
|
||
describe("generateInboxId", () => { | ||
it("should generate an inbox id", () => { | ||
const user = createUser(); | ||
const inboxId = generateInboxId(user.account.address); | ||
expect(inboxId).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe("getInboxIdForAddress", () => { | ||
it("should return `null` inbox ID for unregistered address", async () => { | ||
const user = createUser(); | ||
const inboxId = await getInboxIdForAddress(user.account.address, "local"); | ||
expect(inboxId).toBe(null); | ||
}); | ||
|
||
it("should return inbox ID for registered address", async () => { | ||
const user = createUser(); | ||
const client = await createRegisteredClient(user); | ||
const inboxId = await getInboxIdForAddress(user.account.address, "local"); | ||
expect(inboxId).toBe(client.inboxId); | ||
}); | ||
}); |