@onekeyfe/react-native-native-list 6.7.0-alpha.327 → 6.7.0-alpha.335

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/docs/SPEC.md +390 -9
  2. package/lib/module/NativeList.js +2 -0
  3. package/lib/module/NativeList.web.js +140 -29
  4. package/lib/module/validation.js +143 -34
  5. package/lib/module/web/NativeListWebEngine.js +356 -62
  6. package/lib/module/web/templates/ActivityRowRenderer.js +484 -5
  7. package/lib/module/web/templates/MarketRowRenderer.js +8 -3
  8. package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
  9. package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
  10. package/lib/module/web/templates/RowRendererRegistry.js +5 -3
  11. package/lib/module/web/templates/SectionHeaderRowRenderer.js +34 -1
  12. package/lib/typescript/src/NativeList.types.d.ts +11 -1
  13. package/lib/typescript/src/NativeList.web.d.ts +2 -2
  14. package/lib/typescript/src/models.d.ts +71 -1
  15. package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -1
  16. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
  17. package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
  18. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
  19. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +1 -1
  20. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
  21. package/package.json +3 -3
  22. package/src/NativeList.tsx +2 -0
  23. package/src/NativeList.types.ts +12 -1
  24. package/src/NativeList.web.tsx +191 -38
  25. package/src/models.ts +93 -0
  26. package/src/validation.ts +348 -58
  27. package/src/web/NativeListWebEngine.ts +603 -95
  28. package/src/web/templates/ActivityRowRenderer.ts +723 -7
  29. package/src/web/templates/MarketRowRenderer.ts +19 -3
  30. package/src/web/templates/MarketTableRowRenderer.ts +755 -0
  31. package/src/web/templates/MediaTileRowRenderer.ts +313 -5
  32. package/src/web/templates/RowRendererRegistry.ts +10 -5
  33. package/src/web/templates/SectionHeaderRowRenderer.ts +42 -1
package/src/validation.ts CHANGED
@@ -14,6 +14,9 @@ import type {
14
14
  RowModel,
15
15
  RowPatch,
16
16
  WalletGroupRow,
17
+ WebMarketTableCell,
18
+ WebMarketTablePresentation,
19
+ WebMarketTableText,
17
20
  } from './models';
18
21
 
19
22
  const MAX_KEY_LENGTH = 256;
@@ -594,67 +597,12 @@ function normalizeRowStyles<T extends RowModel>(row: T): T {
594
597
  return next as T;
595
598
  }
596
599
 
597
- function assertMarketRow(row: MarketRow, path: string): void {
598
- if (!['token', 'stock', 'perp'].includes(row.variant)) {
599
- fail(`${path}.variant`, 'must be token, stock, or perp');
600
- }
601
- assertText(row.title, `${path}.title`);
602
- assertText(row.subtitle, `${path}.subtitle`);
603
- // OneKey patch: validate the independently laid out Market name.
604
- if (row.subtitlePrefix) {
605
- assertText(row.subtitlePrefix.text, `${path}.subtitlePrefix.text`);
606
- assertBoundedStyleNumber(
607
- row.subtitlePrefix.gap,
608
- `${path}.subtitlePrefix.gap`,
609
- 0,
610
- 64
611
- );
612
- assertBoundedStyleNumber(
613
- row.subtitlePrefix.maxWidth,
614
- `${path}.subtitlePrefix.maxWidth`,
615
- 1,
616
- 320
617
- );
618
- assertTextStyle(row.subtitlePrefix.style, `${path}.subtitlePrefix.style`);
619
- }
620
- assertText(row.price, `${path}.price`);
621
- assertText(row.change.text, `${path}.change.text`);
622
- assertTrailingAccessories(
623
- row.leadingAction ? [row.leadingAction] : undefined,
624
- `${path}.leadingAction`
625
- );
626
- if (row.leadingAction) {
627
- assertText(row.leadingAction.name, `${path}.leadingAction.name`);
628
- if (row.leadingAction.actionKey !== undefined) {
629
- assertKey(row.leadingAction.actionKey, `${path}.leadingAction.actionKey`);
630
- }
631
- }
632
- assertLeadingVisual(row.leading, `${path}.leading`);
633
- const assertSegments = (
634
- segments: MarketRow['priceSegments'],
635
- segmentPath: string
636
- ) => {
637
- segments?.forEach((segment, index) => {
638
- assertText(segment.text, `${segmentPath}[${index}].text`);
639
- if (segment.style !== undefined && segment.style !== 'subscript') {
640
- fail(
641
- `${segmentPath}[${index}].style`,
642
- 'must be subscript when provided'
643
- );
644
- }
645
- });
646
- };
647
- assertSegments(row.subtitleSegments, `${path}.subtitleSegments`);
648
- assertSegments(row.priceSegments, `${path}.priceSegments`);
649
- assertSegments(row.change.textSegments, `${path}.change.textSegments`);
650
- if (!['positive', 'negative', 'neutral'].includes(row.change.tone)) {
651
- fail(`${path}.change.tone`, 'must be positive, negative, or neutral');
652
- }
653
- if ((row.badges?.length ?? 0) > MAX_MARKET_BADGES) {
600
+ function assertMarketBadges(badges: MarketRow['badges'], path: string): void {
601
+ if ((badges?.length ?? 0) > MAX_MARKET_BADGES) {
654
602
  fail(`${path}.badges`, `supports at most ${MAX_MARKET_BADGES} badges`);
655
603
  }
656
604
  const badgeKeys = new Set<string>();
657
- row.badges?.forEach((badge, index) => {
605
+ badges?.forEach((badge, index) => {
658
606
  const badgePath = `${path}.badges[${index}]`;
659
607
  assertKey(badge.key, `${badgePath}.key`);
660
608
  if (badgeKeys.has(badge.key)) {
@@ -709,6 +657,322 @@ function assertMarketRow(row: MarketRow, path: string): void {
709
657
  assertKey(badge.actionKey, `${badgePath}.actionKey`);
710
658
  }
711
659
  });
660
+ }
661
+
662
+ function assertWebMarketTable(
663
+ table: WebMarketTablePresentation | undefined,
664
+ path: string
665
+ ): void {
666
+ if (!table) return;
667
+ assertUnknownKeys(
668
+ table,
669
+ ['columns', 'cells', 'testID', 'draggable', 'contextMenuActionKey'],
670
+ path,
671
+ 'Web table key'
672
+ );
673
+ if (table.draggable !== undefined && typeof table.draggable !== 'boolean')
674
+ fail(`${path}.draggable`, 'must be boolean');
675
+ if (table.contextMenuActionKey !== undefined)
676
+ assertKey(table.contextMenuActionKey, `${path}.contextMenuActionKey`);
677
+ assertText(table.testID, `${path}.testID`);
678
+ if (
679
+ !Array.isArray(table.columns) ||
680
+ table.columns.length < 1 ||
681
+ table.columns.length > 12
682
+ )
683
+ fail(`${path}.columns`, 'must contain 1...12 columns');
684
+ if (
685
+ !Array.isArray(table.cells) ||
686
+ table.cells.length !== table.columns.length
687
+ )
688
+ fail(`${path}.cells`, 'must match the column count');
689
+ const keys = new Set<string>();
690
+ table.columns.forEach((column, index) => {
691
+ const field = `${path}.columns[${index}]`;
692
+ assertUnknownKeys(
693
+ column,
694
+ [
695
+ 'key',
696
+ 'width',
697
+ 'minWidth',
698
+ 'flex',
699
+ 'alignment',
700
+ 'paddingStart',
701
+ 'paddingEnd',
702
+ ],
703
+ field,
704
+ 'Web column key'
705
+ );
706
+ assertKey(column.key, `${field}.key`);
707
+ if (keys.has(column.key)) fail(field, 'column keys must be unique');
708
+ keys.add(column.key);
709
+ assertBoundedStyleNumber(column.width, `${field}.width`, 0, 4096);
710
+ assertBoundedStyleNumber(column.minWidth, `${field}.minWidth`, 0, 4096);
711
+ assertBoundedStyleNumber(column.flex, `${field}.flex`, 0, 16);
712
+ assertBoundedStyleNumber(
713
+ column.paddingStart,
714
+ `${field}.paddingStart`,
715
+ 0,
716
+ 64
717
+ );
718
+ assertBoundedStyleNumber(column.paddingEnd, `${field}.paddingEnd`, 0, 64);
719
+ if (
720
+ column.alignment !== undefined &&
721
+ !['start', 'center', 'end'].includes(column.alignment)
722
+ )
723
+ fail(`${field}.alignment`, 'must be start, center, or end');
724
+ });
725
+ const text = (value: WebMarketTableText, field: string) => {
726
+ assertUnknownKeys(
727
+ value,
728
+ ['text', 'segments', 'tone', 'style'],
729
+ field,
730
+ 'Web text key'
731
+ );
732
+ assertText(value.text, `${field}.text`);
733
+ assertTextTone(value.tone, `${field}.tone`);
734
+ assertTextStyle(value.style, `${field}.style`);
735
+ if (value.style)
736
+ assertUnknownKeys(
737
+ value.style,
738
+ ['fontSize', 'fontWeight', 'lineHeight', 'color'],
739
+ `${field}.style`,
740
+ 'Web table text style'
741
+ );
742
+ if ((value.segments?.length ?? 0) > 64)
743
+ fail(`${field}.segments`, 'supports at most 64 segments');
744
+ value.segments?.forEach((segment, index) => {
745
+ assertUnknownKeys(
746
+ segment,
747
+ ['text', 'style'],
748
+ `${field}.segments[${index}]`,
749
+ 'Web text segment'
750
+ );
751
+ assertText(segment.text, `${field}.segments[${index}].text`);
752
+ if (segment.style !== undefined && segment.style !== 'subscript')
753
+ fail(field, 'segment style must be subscript');
754
+ });
755
+ };
756
+ const line = (
757
+ parts: readonly WebMarketTableText[] | undefined,
758
+ field: string
759
+ ) => {
760
+ if (!parts) return;
761
+ if (!Array.isArray(parts) || parts.length > 8)
762
+ fail(field, 'supports at most 8 text parts');
763
+ parts.forEach((value, index) => text(value, `${field}[${index}]`));
764
+ };
765
+ table.cells.forEach((cell: WebMarketTableCell, index) => {
766
+ const field = `${path}.cells[${index}]`;
767
+ assertKey(cell.key, `${field}.key`);
768
+ if (cell.key !== table.columns[index].key)
769
+ fail(field, 'cell key/order must match its column');
770
+ switch (cell.kind) {
771
+ case 'favorite':
772
+ assertUnknownKeys(
773
+ cell,
774
+ [
775
+ 'key',
776
+ 'kind',
777
+ 'active',
778
+ 'disabled',
779
+ 'testID',
780
+ 'hoverActionKey',
781
+ 'actionKey',
782
+ 'accessibilityLabel',
783
+ ],
784
+ field,
785
+ 'Web favorite key'
786
+ );
787
+ if (typeof cell.active !== 'boolean')
788
+ fail(field, 'active must be boolean');
789
+ if (cell.disabled !== undefined && typeof cell.disabled !== 'boolean')
790
+ fail(field, 'disabled must be boolean');
791
+ if (cell.hoverActionKey !== undefined)
792
+ assertKey(cell.hoverActionKey, `${field}.hoverActionKey`);
793
+ assertText(cell.testID, `${field}.testID`);
794
+ assertKey(cell.actionKey, `${field}.actionKey`);
795
+ assertText(cell.accessibilityLabel, `${field}.accessibilityLabel`);
796
+ break;
797
+ case 'asset':
798
+ assertUnknownKeys(
799
+ cell,
800
+ [
801
+ 'key',
802
+ 'kind',
803
+ 'leading',
804
+ 'title',
805
+ 'secondary',
806
+ 'hoverSecondary',
807
+ 'hoverActionKey',
808
+ 'hoverActionLabel',
809
+ 'badges',
810
+ 'lineGap',
811
+ 'secondaryBadges',
812
+ 'hoverImages',
813
+ ],
814
+ field,
815
+ 'Web asset key'
816
+ );
817
+ assertBoundedStyleNumber(cell.lineGap, `${field}.lineGap`, 0, 8);
818
+ assertMarketBadges(cell.secondaryBadges, `${field}.secondary`);
819
+ cell.secondaryBadges?.forEach((badge, i) => {
820
+ assertUnknownKeys(
821
+ badge,
822
+ ['key', 'text', 'style'],
823
+ `${field}.secondaryBadges[${i}]`,
824
+ 'Web secondary badge key'
825
+ );
826
+ if (!badge.text) fail(field, 'secondary badges require text');
827
+ });
828
+ if (
829
+ cell.hoverImages !== undefined &&
830
+ (!Array.isArray(cell.hoverImages) || cell.hoverImages.length > 4)
831
+ )
832
+ fail(field, 'supports at most 4 hover images');
833
+ cell.hoverImages?.forEach((image, i) => {
834
+ if (image !== null) assertImage(image, `${field}.hoverImages[${i}]`);
835
+ });
836
+ assertLeadingVisual(cell.leading, `${field}.leading`);
837
+ text(cell.title, `${field}.title`);
838
+ line(cell.secondary, `${field}.secondary`);
839
+ line(cell.hoverSecondary, `${field}.hoverSecondary`);
840
+ assertText(cell.hoverActionLabel, `${field}.hoverActionLabel`);
841
+ if (cell.hoverActionKey !== undefined)
842
+ assertKey(cell.hoverActionKey, `${field}.hoverActionKey`);
843
+ assertMarketBadges(cell.badges, field);
844
+ cell.badges?.forEach((badge, i) =>
845
+ assertUnknownKeys(
846
+ badge,
847
+ [
848
+ 'key',
849
+ 'text',
850
+ 'iconName',
851
+ 'icon',
852
+ 'textColor',
853
+ 'backgroundColor',
854
+ 'actionKey',
855
+ 'accessibilityLabel',
856
+ 'style',
857
+ ],
858
+ `${field}.badges[${i}]`,
859
+ 'Web title badge key'
860
+ )
861
+ );
862
+ break;
863
+ case 'text':
864
+ assertUnknownKeys(
865
+ cell,
866
+ ['key', 'kind', 'primary', 'secondary', 'partGap'],
867
+ field,
868
+ 'Web text cell key'
869
+ );
870
+ assertBoundedStyleNumber(cell.partGap, `${field}.partGap`, 0, 8);
871
+ if (!Array.isArray(cell.primary) || !cell.primary.length)
872
+ fail(field, 'requires primary text');
873
+ line(cell.primary, `${field}.primary`);
874
+ line(cell.secondary, `${field}.secondary`);
875
+ break;
876
+ case 'sparkline':
877
+ assertUnknownKeys(
878
+ cell,
879
+ [
880
+ 'key',
881
+ 'kind',
882
+ 'points',
883
+ 'width',
884
+ 'height',
885
+ 'strokeColor',
886
+ 'fillColor',
887
+ ],
888
+ field,
889
+ 'Web sparkline key'
890
+ );
891
+ if (
892
+ !Array.isArray(cell.points) ||
893
+ cell.points.length > 256 ||
894
+ cell.points.some((value: number) => !Number.isFinite(value))
895
+ )
896
+ fail(field, 'supports at most 256 finite samples');
897
+ if (typeof cell.width !== 'number' || typeof cell.height !== 'number')
898
+ fail(field, 'sparkline dimensions are required');
899
+ assertBoundedStyleNumber(cell.width, `${field}.width`, 1, 512);
900
+ assertBoundedStyleNumber(cell.height, `${field}.height`, 1, 512);
901
+ for (const color of [cell.strokeColor, cell.fillColor])
902
+ if (
903
+ typeof color !== 'string' ||
904
+ !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(color)
905
+ )
906
+ fail(field, 'colors must be #RRGGBB or #RRGGBBAA');
907
+ break;
908
+ default:
909
+ fail(field, 'unsupported Web table cell kind');
910
+ }
911
+ });
912
+ }
913
+
914
+ function assertMarketRow(row: MarketRow, path: string): void {
915
+ assertWebMarketTable(row.webTable, `${path}.webTable`);
916
+ if (!['token', 'stock', 'perp'].includes(row.variant)) {
917
+ fail(`${path}.variant`, 'must be token, stock, or perp');
918
+ }
919
+ assertText(row.title, `${path}.title`);
920
+ assertText(row.subtitle, `${path}.subtitle`);
921
+ // OneKey patch: validate the independently laid out Market name.
922
+ if (row.subtitlePrefix) {
923
+ assertText(row.subtitlePrefix.text, `${path}.subtitlePrefix.text`);
924
+ assertText(
925
+ row.subtitlePrefix.hoverActionKey,
926
+ `${path}.subtitlePrefix.hoverActionKey`
927
+ );
928
+ assertBoundedStyleNumber(
929
+ row.subtitlePrefix.gap,
930
+ `${path}.subtitlePrefix.gap`,
931
+ 0,
932
+ 64
933
+ );
934
+ assertBoundedStyleNumber(
935
+ row.subtitlePrefix.maxWidth,
936
+ `${path}.subtitlePrefix.maxWidth`,
937
+ 1,
938
+ 320
939
+ );
940
+ assertTextStyle(row.subtitlePrefix.style, `${path}.subtitlePrefix.style`);
941
+ }
942
+ assertText(row.price, `${path}.price`);
943
+ assertText(row.change.text, `${path}.change.text`);
944
+ assertTrailingAccessories(
945
+ row.leadingAction ? [row.leadingAction] : undefined,
946
+ `${path}.leadingAction`
947
+ );
948
+ if (row.leadingAction) {
949
+ assertText(row.leadingAction.name, `${path}.leadingAction.name`);
950
+ if (row.leadingAction.actionKey !== undefined) {
951
+ assertKey(row.leadingAction.actionKey, `${path}.leadingAction.actionKey`);
952
+ }
953
+ }
954
+ assertLeadingVisual(row.leading, `${path}.leading`);
955
+ const assertSegments = (
956
+ segments: MarketRow['priceSegments'],
957
+ segmentPath: string
958
+ ) => {
959
+ segments?.forEach((segment, index) => {
960
+ assertText(segment.text, `${segmentPath}[${index}].text`);
961
+ if (segment.style !== undefined && segment.style !== 'subscript') {
962
+ fail(
963
+ `${segmentPath}[${index}].style`,
964
+ 'must be subscript when provided'
965
+ );
966
+ }
967
+ });
968
+ };
969
+ assertSegments(row.subtitleSegments, `${path}.subtitleSegments`);
970
+ assertSegments(row.priceSegments, `${path}.priceSegments`);
971
+ assertSegments(row.change.textSegments, `${path}.change.textSegments`);
972
+ if (!['positive', 'negative', 'neutral'].includes(row.change.tone)) {
973
+ fail(`${path}.change.tone`, 'must be positive, negative, or neutral');
974
+ }
975
+ assertMarketBadges(row.badges, path);
712
976
  for (const [key, value] of [
713
977
  ['pressActionKey', row.pressActionKey],
714
978
  ['pressInActionKey', row.pressInActionKey],
@@ -769,6 +1033,15 @@ function assertTrailingAccessories(
769
1033
  function assertImage(image: ImageSource | undefined, path: string): void {
770
1034
  if (!image) return;
771
1035
  if (!image.uri.trim()) fail(`${path}.uri`, 'must not be empty');
1036
+ if (image.fallbackUris !== undefined) {
1037
+ if (!Array.isArray(image.fallbackUris))
1038
+ fail(`${path}.fallbackUris`, 'must be an array');
1039
+ image.fallbackUris.forEach((uri, index) => {
1040
+ if (typeof uri !== 'string')
1041
+ fail(`${path}.fallbackUris[${index}]`, 'must be a string');
1042
+ assertText(uri, `${path}.fallbackUris[${index}]`);
1043
+ });
1044
+ }
772
1045
  if (
773
1046
  !Number.isFinite(image.width) ||
774
1047
  !Number.isFinite(image.height) ||
@@ -1418,6 +1691,10 @@ export function validateSnapshot(
1418
1691
  );
1419
1692
 
1420
1693
  assertPlainSerializable(snapshot, 'snapshot', new Set<object>());
1694
+ assertText(
1695
+ snapshot.theme?.imageFallbackBackground,
1696
+ 'theme.imageFallbackBackground'
1697
+ );
1421
1698
  if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
1422
1699
  if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) {
1423
1700
  fail('snapshot.generation', 'must be a non-negative safe integer');
@@ -1848,6 +2125,19 @@ export function applyRowPatches(
1848
2125
  if (patch.type !== row.type) {
1849
2126
  fail('patches', `row "${row.key}" is ${row.type}, not ${patch.type}`);
1850
2127
  }
2128
+ if (
2129
+ row.type === 'market' &&
2130
+ row.webTable &&
2131
+ patch.type === 'market' &&
2132
+ (patch.changes.price !== undefined ||
2133
+ patch.changes.priceSegments !== undefined ||
2134
+ patch.changes.change !== undefined) &&
2135
+ patch.changes.webTable === undefined
2136
+ )
2137
+ fail(
2138
+ 'patches',
2139
+ 'table quote changes must include the visible table cells'
2140
+ );
1851
2141
  return {
1852
2142
  ...row,
1853
2143
  ...patch.changes,