From 73269d1faf7c0ac23f9c036134d2b958cec1a371 Mon Sep 17 00:00:00 2001 From: James Pacheco Date: Tue, 26 Apr 2022 17:39:27 -0600 Subject: [PATCH] Update sorting --- coordinators/MovieCoordinator.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/coordinators/MovieCoordinator.ts b/coordinators/MovieCoordinator.ts index 0126e59..ddfe77c 100644 --- a/coordinators/MovieCoordinator.ts +++ b/coordinators/MovieCoordinator.ts @@ -7,7 +7,6 @@ const MOVIE_REVIEW_PROGRAM_ID = 'CenYq6bDRB7p73EjsPEpiYN7uveyPUTdXkDkgUduboaN' export class MovieCoordinator { static accounts: web3.PublicKey[] = [] - static async prefetchAccounts(connection: web3.Connection, search: string) { const accounts = await connection.getProgramAccounts( new web3.PublicKey(MOVIE_REVIEW_PROGRAM_ID), @@ -26,7 +25,11 @@ export class MovieCoordinator { ) accounts.sort( (a, b) => { - return a.account.data.slice(4, 4 + a.account.data[0]).compare(b.account.data.slice(4, 4 + b.account.data[0])) + const lengthA = a.account.data.readUInt32LE(0) + const lengthB = b.account.data.readUInt32LE(0) + const dataA = a.account.data.slice(4, 4 + lengthA) + const dataB = b.account.data.slice(4, 4 + lengthB) + return dataA.compare(dataB) }) this.accounts = accounts.map(account => account.pubkey)