-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web-stub): implement directory module
- add initial accounts on mock - breaking; add test event - adjust tests
- Loading branch information
Showing
11 changed files
with
285 additions
and
58 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
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,69 @@ | ||
import { Account, AccountId, AccountIdentity } from "@ticketto/types"; | ||
|
||
import { DirectoryCalls, DirectoryStorage } from "@ticketto/protocol"; | ||
import { IDBPDatabase } from "idb"; | ||
import { TickettoDBSchema } from "./types.js"; | ||
import { inject, injectable } from "inversify"; | ||
|
||
function boundedByString(s: string): [string, string] { | ||
const inc = (s: string) => | ||
s === "" ? "" : String.fromCharCode(s.charCodeAt(0) + 1); | ||
|
||
const letters = s.split(""); | ||
const lastChar = letters.pop(); | ||
|
||
return [s, letters.concat(inc(lastChar ?? "")).join("")]; | ||
} | ||
|
||
@injectable() | ||
export class WebStubDirectoryStorage implements DirectoryStorage { | ||
constructor( | ||
@inject("TickettoDB") private db: IDBPDatabase<TickettoDBSchema> | ||
) {} | ||
|
||
all(): Promise<Account[]> { | ||
return this.db.getAll("accounts"); | ||
} | ||
|
||
indexByDisplay(display: string): Promise<Account[]> { | ||
return this.db.getAllFromIndex( | ||
"accounts", | ||
"display", | ||
IDBKeyRange.bound(...boundedByString(display)) | ||
); | ||
} | ||
|
||
indexByPhone(phone: string): Promise<Account[]> { | ||
return this.db.getAllFromIndex( | ||
"accounts", | ||
"phone", | ||
IDBKeyRange.bound(...boundedByString(phone)) | ||
); | ||
} | ||
|
||
indexByEmail(email: string): Promise<Account[]> { | ||
return this.db.getAllFromIndex( | ||
"accounts", | ||
"email", | ||
IDBKeyRange.bound(...boundedByString(email)) | ||
); | ||
} | ||
|
||
get(accountId: AccountId): Promise<Account | undefined> { | ||
return this.db.get("accounts", accountId); | ||
} | ||
} | ||
|
||
@injectable() | ||
export class WebStubDirectoryCalls implements DirectoryCalls { | ||
insert(accountId: AccountId, identity: AccountIdentity): Promise<void> { | ||
throw new Error("Method not implemented."); | ||
} | ||
|
||
setIdentity( | ||
accountId: AccountId, | ||
identity: Partial<AccountIdentity> | ||
): Promise<void> { | ||
throw new Error("Method not implemented."); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,28 +1,59 @@ | ||
import { StubGenesisConfig } from "../types.js"; | ||
|
||
const zero = { | ||
free: 0, | ||
reserved: 0, | ||
frozen: 0, | ||
}; | ||
|
||
export default { | ||
accounts: [ | ||
{ | ||
id: "5DD8bv4RnTDuJt47SAjpWMT78N7gfBQNF2YiZpVUgbXkizMG", | ||
identity: { | ||
legalName: "Alice", | ||
display: "alice", | ||
firstName: "Alice", | ||
lastName: "Anon", | ||
phone: "1.4168900514", | ||
email: "[email protected]", | ||
additional: [], | ||
}, | ||
balance: 0, | ||
balance: zero, | ||
assets: {}, | ||
}, | ||
{ | ||
id: "5HVoCpiwRWMZCmM8ituz46JVGAzvAjqsHrGkdhqrDUD4NW6o", | ||
identity: { | ||
legalName: "Bob", | ||
display: "bob", | ||
firstName: "Bob", | ||
lastName: "Bear", | ||
phone: "1.4158900514", | ||
email: "[email protected]", | ||
additional: [], | ||
}, | ||
balance: 0, | ||
balance: zero, | ||
assets: {}, | ||
}, | ||
], | ||
events: [ | ||
{ | ||
id: 1, | ||
owner: "5Fh3tNPUUKtApDZ6rJ2sDgcC5Z6pVVyAzKeE1dnqowLqWEvw", | ||
name: "Dua Lipa en Colombia", | ||
description: "Dua lipa viene a Colombia, no te lo pierdas", | ||
banner: | ||
"https://lumiere-a.akamaihd.net/v1/images/dua_lipa_portada_5_bf1628a4.jpeg?region=15,0,1956,1100&width=960", | ||
dates: [ | ||
[1710446400000, 1710475200000], | ||
[1710532800000, 1710561600000], | ||
[1710619200000, 1710648000000], | ||
], | ||
date: [1710446400000, 1710475200000], | ||
capacity: 24000, | ||
}, | ||
{ | ||
id: 2, | ||
owner: "5Fh3tNPUUKtApDZ6rJ2sDgcC5Z6pVVyAzKeE1dnqowLqWEvw", | ||
name: "Mitú", | ||
description: "Mitú Astra Tour 2023\n\nCon Charlie Florez, Varez y Puerto", | ||
banner: | ||
|
@@ -32,7 +63,7 @@ export default { | |
date: [1709762400000, 1709776800000], | ||
}, | ||
{ | ||
id: 2, | ||
id: 3, | ||
owner: "5Fh3tNPUUKtApDZ6rJ2sDgcC5Z6pVVyAzKeE1dnqowLqWEvw", | ||
name: "Dlina Volny", | ||
description: | ||
|
@@ -44,7 +75,7 @@ export default { | |
date: [1712345600000, 1712360000000], | ||
}, | ||
{ | ||
id: 3, | ||
id: 4, | ||
owner: "5Fh3tNPUUKtApDZ6rJ2sDgcC5Z6pVVyAzKeE1dnqowLqWEvw", | ||
name: "Paula Garcés - Laura Villalobos - Martin Arc - BT.MKR", | ||
description: | ||
|
@@ -56,12 +87,12 @@ export default { | |
}, | ||
], | ||
tickets: [ | ||
// Event: Mitú | ||
// Event: Dua Lipa en Colombia | ||
{ | ||
id: 1, | ||
issuer: 1, | ||
owner: "5DD8bv4RnTDuJt47SAjpWMT78N7gfBQNF2YiZpVUgbXkizMG", | ||
name: "Mitú", | ||
name: "Dua Lipa en Colombia", | ||
description: "General Entrance", | ||
ticketArt: | ||
"https://wild-presenta.com/wp-content/uploads/2023/07/MITU-ASTRATOURTUNJA19AGOSTO.jpg", | ||
|
@@ -75,7 +106,7 @@ export default { | |
id: 2, | ||
issuer: 1, | ||
owner: "5HVoCpiwRWMZCmM8ituz46JVGAzvAjqsHrGkdhqrDUD4NW6o", | ||
name: "Mitú", | ||
name: "Dua Lipa en Colombia", | ||
description: "General Entrance", | ||
ticketArt: | ||
"https://wild-presenta.com/wp-content/uploads/2023/07/MITU-ASTRATOURTUNJA19AGOSTO.jpg", | ||
|
@@ -85,12 +116,12 @@ export default { | |
type: "Single", | ||
}, | ||
}, | ||
// Event: Dlina Volny | ||
// Event: Mitú | ||
{ | ||
id: 1, | ||
issuer: 2, | ||
owner: "5DD8bv4RnTDuJt47SAjpWMT78N7gfBQNF2YiZpVUgbXkizMG", | ||
name: "Dlina Volny", | ||
name: "Mitú", | ||
ticketArt: | ||
"https://wild-presenta.com/wp-content/uploads/2023/07/Copia-de-FINAL.jpg", | ||
description: "General Entrance", | ||
|
@@ -104,7 +135,7 @@ export default { | |
id: 2, | ||
issuer: 2, | ||
owner: "5HVoCpiwRWMZCmM8ituz46JVGAzvAjqsHrGkdhqrDUD4NW6o", | ||
name: "Dlina Volny", | ||
name: "Mitú", | ||
ticketArt: | ||
"https://wild-presenta.com/wp-content/uploads/2023/07/Copia-de-FINAL.jpg", | ||
description: "General Entrance", | ||
|
@@ -114,11 +145,26 @@ export default { | |
type: "Single", | ||
}, | ||
}, | ||
// Event: Paula Garcés - Laura Villalobos - Martin Arc - BT.MKR | ||
// Event: Dlina Volny | ||
{ | ||
id: 1, | ||
issuer: 3, | ||
owner: "5DD8bv4RnTDuJt47SAjpWMT78N7gfBQNF2YiZpVUgbXkizMG", | ||
name: "Dlina Volny", | ||
ticketArt: | ||
"https://wild-presenta.com/wp-content/uploads/2024/01/FLYER.jpg", | ||
description: "General Entrance", | ||
attendances: [], | ||
forSale: false, | ||
attedancePolicy: { | ||
type: "Single", | ||
}, | ||
}, | ||
// Event: Paula Garcés - Laura Villalobos - Martin Arc - BT.MKR | ||
{ | ||
id: 1, | ||
issuer: 4, | ||
owner: "5HVoCpiwRWMZCmM8ituz46JVGAzvAjqsHrGkdhqrDUD4NW6o", | ||
name: "Paula Garcés - Laura Villalobos - Martin Arc - BT.MKR", | ||
ticketArt: | ||
"https://wild-presenta.com/wp-content/uploads/2024/01/FLYER.jpg", | ||
|
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
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,8 @@ | ||
import { type ClientConfig } from "@ticketto/protocol"; | ||
|
||
export const defaultConfig: ClientConfig = { | ||
accountProvider: { | ||
getAccountId: () => "5DD8bv4RnTDuJt47SAjpWMT78N7gfBQNF2YiZpVUgbXkizMG", | ||
sign: (payload) => Promise.resolve(payload), | ||
}, | ||
}; |
Oops, something went wrong.